简体   繁体   English

How to plot graph using plot function inside a function using if loop in R

[英]How to plot graph using plot function inside a function using if loop in R

crime.value = 1

crime.bar <- function() {
  bp<-ggplot(df_category, aes(x=Category, y=Frequency, fill=Category)) + geom_bar(stat="identity") + 
    theme(axis.text.x=element_blank())
  bp
}

  if (crime.value == 1) {
    crime.bar()
  }

The Plot function works when i call crime.bar() seperately. Plot function 在我单独调用crime.bar()时起作用。 but when called through a if loop it doesn't work.但是当通过 if 循环调用时,它不起作用。 please help.请帮忙。

You need to use print(bp) within the loop to force the output.您需要在循环中使用print(bp)来强制 output。 Thanks to @Dave2e感谢@Dave2e

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM