Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
闪亮,R:复选框,geom_hline,ggplot_R_Checkbox_Ggplot2_Shiny_Geom Hline - Fatal编程技术网

闪亮,R:复选框,geom_hline,ggplot

闪亮,R:复选框,geom_hline,ggplot,r,checkbox,ggplot2,shiny,geom-hline,R,Checkbox,Ggplot2,Shiny,Geom Hline,在我的闪亮应用程序中,我只想在用户选中复选框时在ggplot中添加geom_hline,我还希望用户使用数字输入设置yintercept。 我相信有一个简单的解决办法,但由于我不是一个编码员,我想问哪种方法最简单。 我的代码是这样的: 在UI中: numericInput('hline', label ='Limits', 0) 和在服务器中: plotInput <- reactive({ ggplot(data = dataforplot(), aes(x = ID_

在我的闪亮应用程序中,我只想在用户选中复选框时在ggplot中添加geom_hline,我还希望用户使用数字输入设置yintercept。 我相信有一个简单的解决办法,但由于我不是一个编码员,我想问哪种方法最简单。 我的代码是这样的:

在UI中:

numericInput('hline', label ='Limits', 0)
和在服务器中:

 plotInput <- reactive({



    ggplot(data = dataforplot(), aes(x = ID_Polymer, y = value), position = position_dodge(width = 1))  +
      geom_bar(aes_string( fill=razeni()), position = position_dodge(width = 1), stat="identity", color="white")+
      theme_minimal() +
      theme(legend.text=element_text(size=21))+
      theme(text = element_text(size=21))+
      theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
      ggtitle(input$title_text_box_id) + 

      geom_hline(aes(yintercept = input$hline, linetype = "Minimal limit"), color='red', size=0.4)+

      labs(x = "", y = input$ylabel_text_box_id) + 
      geom_text(aes(x = ID_Polymer, y = value,Group=Polymer,label=value), 
                position = position_dodge(width = 1),vjust=2, size=5,colour = "white", fontface = "bold") +
      scale_fill_tableau("Tableau 10")+
     scale_x_discrete(labels=c(xpopisky()))#puts a reactive in x labels

  })
这是可行的,只是我不知道最好的方式告诉闪亮的显示几何图形只有当我通过勾选复选框告诉你时,我相信应该涉及一个if-else循环。
谢谢你的建议

可以将ggplot对象指定给变量。以下伪代码演示了这一点:

p = ggplot(data = ......) +
      geom_bar(....) +
      theme(....)

if(input$hline){
    p = p + geom_hline(....)
}
请注意,如果您提供一个最少的工作示例,您的问题将得到改进。现在,您问题中的代码包含不相关的细节,例如ggplot主题和标签,无法按原样运行