我有一个闪亮的应用程序,可以在其中制作不同临床参数的ggplot。由于不同的临床参数包含不同的组,因此统计检验会有所不同。如何根据下拉菜单中的临床参数为stat_compare_means
定义不同的组?
这是应用程序: https://mjellelab.shinyapps.io/SHINY_miRNA_CLINICAL/
例如,对于血清成分_m_component,我想将所有四个组彼此进行比较(未知除外),在ISS阶段,我要比较1vs2、1vs3和2vs3。
app:
data_prep <-
structure(list(miRNA = c("hsa-let-7a-3p", "hsa-let-7a-3p", "hsa-let-7a-3p",
"hsa-let-7a-3p", "hsa-let-7a-3p", "hsa-let-7a-3p"), ID = c("86",
"175", "217", "394", "444", "618"), value = c(5.57979757386892,
5.21619202802748, 5.42796072966512, -1.1390337316217, 5.06134249676025,
4.37364284462968), Bone_disease = c("Without bone disease", "With bone disease",
"With bone disease", "With bone disease", "With bone disease",
"With bone disease"), Serum_M_component = structure(c(3L, 3L,
5L, 3L, 1L, 3L), .Label = c("IgA", "IgD", "IgG", "LightChains",
"Unknown"), class = "factor"), ISS_stage = c("Stage 3", "Stage 1",
"Stage 3", "Stage 2", "Unknown", "Unknown")), row.names = c(NA,
6L), class = "data.frame")
ui.miRNA.clinical <- dashboardPage(
# Application title
dashboardHeader(title=h4(HTML("MicroRNA expression <br/> in Multiple myeloma"))),
dashboardSidebar(
selectInput("p", "Clinical parameter", choices = c("Bone_disease", "Serum_M_component","ISS_stage")),
selectInput("gene", "MicroRNA", choices = unique(data_prep$miRNA))),
dashboardBody(
tabsetPanel(
tabPanel("Plot", plotOutput("myplot", width = "400px", height = "300px"))
)
)
)
server.miRNA.clinical <- function(input, output, session) {
# filter data by Gene
data_selected <- reactive({
filter(data_prep, miRNA %in% input$gene)
})
output$myplot <- renderPlot({
ggplot(data_selected(), aes_string(input$p, "value", fill = input$p)) +
geom_boxplot() + theme_classic(base_size = 12) + labs(x="Clinical parameter",y="MicroRNA expression (cpm,log2)") +
stat_compare_means(method = "anova")
#method ="anova"
})
}