【发布时间】:2021-04-28 05:38:11
【问题描述】:
我只想绘制一张图像,其中 x 命名为不同的样本,y 命名为不同的基因符号。我还想在闪亮中使用 ggplot2 添加 geom_errorbar。
我希望如果我输入一个基因符号,情节会出现在旁边。
但我试了几次,但我不知道为什么它没有显示。
有两个输入文件。一个是每个样本的平均值,另一个是sd值文件。
我的代码示例如下:
library(shiny)
library(ggplot2)
library(ggpubr)
mean_data<-data.frame(Name=c(paste0("Group_",LETTERS[1:20])),
matx<-matrix(sample(1:1000,1000,replace = T),nrow = 20)
)
names(mean_data)[-1]<-c(paste0("Gene_",1:50))
sd_data<-data.frame(Name=c(paste0("Group_",LETTERS[1:20])),
matx<-matrix(runif(1000,5,10),nrow = 20)
)
names(sd_data)[-1]<-c(paste0("Gene_",1:50))
# Define UI for app that draws a histogram ----
ui <- fluidPage(
h4("Gene_FPKM Value Barplot"),
br(),
sidebarLayout(
sidebarPanel(
textInput(inputId = "GeneSymbol",
label = "Input your Gene Symbol:",
value = "", width = NULL, placeholder = 'e.g. Igfbp7,Zzz3'
),
actionButton("button", "show")
),
# Main panel for displaying outputs ----
mainPanel(
plotOutput(outputId = "barplot")
)
)
)
server <- function(input, output) {
gene <- reactive({
gene<-input$GeneSymbol
})
observeEvent(input$button, {
cat("Showing", input$GeneSymbol)
})
p <- reactive({ggplot(data=mean_data,aes_string(x=mean_data$Name,y=mean_data$input$GeneSymbol,fill=randomColor(74)))+
geom_bar(stat='identity',position=position_dodge(0.5),width=0.9)+
geom_errorbar(aes(ymin = mean_data$input$GeneSymbol-totalsd$input$GeneSymbol, ymax = mean_data$input$GeneSymbol+totalsd$input$GeneSymbol),width=.2)+
theme_classic2()+
rotate_x_text(angle = 45)+
theme(legend.position = "none")+
labs(title=input$GeneSymbol,x=NULL,y="FPKM_value")+
theme(plot.title = element_text(hjust = 0.5))+
theme(plot.margin = unit(c(20,1,1,1), "mm"))
})
output$barplot <- renderPlot({
print(p())
})
}
# Create Shiny app ----
shinyApp(ui = ui, server = server)
我知道有很多错误的代码。 我是闪亮的新手。 请帮助这个孩子。 非常感谢!!
【问题讨论】:
-
谁能帮帮我