我对Shiny R应用程序非常陌生。我正在尝试在Shiny R应用程序中对某些数据集进行简单的箱形图绘制。
在这里,我正在文件df.csv
中显示一些示例数据。数据如下所示。显示以下数据的dput
:
structure(list(Samples = structure(1:10,.Label = c("Sample1","Sample10","Sample2","Sample3","Sample4","Sample5","Sample6","Sample7","Sample8","Sample9"),class = "factor"),Type = structure(c(2L,1L,2L,1L),.Label = c("Normal","Tumor"
),A1BG = c(0,0.01869105,0.026705782,0.016576987,0.007636787,0.015756547,0.00609601,0.115575528,0.04717536
),A1BG.AS1 = c(0,0.096652515,0.086710002,0.04683499,0.188283185,0.104318353,0.102735593,0.100064808,0.04717536,0.159745808
),A1CF = c(1.616942802,1.367084444,1.101855892,1.3823884,0.631627098,2.407159505,1.687449785,1.229844138,0.87989414,0.642785868),A2M = c(3.357654845,3.149165846,3.654774122,2.851143092,2.952601867,4.002335454,4.123949457,3.691343955,3.553064673,3.425443559),A2M.AS1 = c(0.217308191,0.08268571,0.297320544,0.101579093,0.020102613,0.35578965,0.288014115,0.145352771,0.043808388,0.104677012),A2ML1 = c(0,0.017949113,0.00984907,0.002289616,0.002100359,0.032146138,0.052275569,0.537892142,0),A2ML1.AS1 = c(0.631627098,0)),row.names = c(NA,-10L),class = "data.frame")
利用以上信息,我正在尝试制作一个闪亮的应用程序。我的代码如下所示:
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("thegene","Gene",choices = c("A2M","A1CF","A2MP1"),selected = "A2M"),radioButtons("colour","Colour of histogram",choices=c("red","green","blue"),selected="red"),width = 3
),mainPanel(
plotOutput("boxplot"),width = 9
)
)
)
server <- function(input,output) {
df <- read.csv("df.csv")
library(reshape2)
library(ggplot2)
library(ggpubr)
library(envstats)
df.m <- melt(df,c("Samples","Type"))
output$boxplot <- renderPlot({
ggplot(data=df.m,aes(x = Type,y = value,fill=variable)) +
geom_boxplot() +
theme_bw(base_size = 14) + xlab("") + ylab("Expression logFPKM") +
theme(axis.text=element_text(size=15,face = "bold",color = "black"),axis.title=element_text(size=15,strip.text = element_text(size=15,color = "black")) +
stat_compare_means(method = "t.test",size=5) + stat_n_text()
})
}
# Run the application
shinyApp(ui = ui,server = server)
因此,我重塑了信息,然后尝试制作一个应用程序,为肿瘤(6个样本)和正常(4个样本)之间的每个基因创建一个箱线图。
我没有看到任何错误,但是我也没有得到期望的结果。我上面的代码的输出如下所示:
1)每种类型下方的方框图中的样本数量错误。
2)对于基因选择,我只能看到三个基因。我在那里看不到其他基因。如何检查其他基因?
3)直方图的颜色也不起作用。
感谢您的帮助。谢谢。