首页 > 解决方案 > geom_smooth 未显示在 ggplot 函数中

问题描述

我正在尝试添加geom_smooth(method = 'loess'),但这并没有出现在情节中。我相信这与数值有关,geom_smooth 没有将输入识别为数字?

> head(CH12F3.miRNA_prep.miRNA)
            miRNA variable     value
1 mmu-let-7a-1-3p       0h 0.5098628
2   mmu-let-7a-5p       0h 0.4286451
3   mmu-let-7b-3p       0h 0.0000000
4   mmu-let-7b-5p       0h 1.4925830
5 mmu-let-7c-2-3p       0h 1.0715206
6   mmu-let-7c-5p       0h 1.3836720

server <- function(input, output, session) {
  
  data_selected <- reactive({
    filter(CH12F3.miRNA_prep.miRNA, miRNA %in% input$MicroRNA)
  })
  
  output$myplot <- renderPlot({

    ggplot(data_selected(), aes_string("variable", "value", colour = "variable")) + 
      geom_point() + theme_classic(base_size = 12) +
      labs(colour="Time Point",x="Time",y="Expression (cpm,log2)\nTreated/Control")+
    theme(axis.text.x = element_text(angle = 45,hjust = 1)) + geom_smooth(method = 'loess')
      
  }    )
}

标签: shiny

解决方案


在您的ggplot, 尝试aes(as.numeric(variable), as.numeric(value), color=variable)而不是aes_string().


推荐阅读