R中带有图形的2组Boxplot :: boxplot

时间:2017-08-31 20:23:43

标签: r boxplot

我有两组数据(顶部和底部),我已经能够单独制作箱图,但无法让它们显示在同一图表中。我希望它们并排进行每个基因测试的比较(总共12个)。所以,我想用测试的基因标记x轴,用ddCt值标记y轴,每个基因有2个箱图(顶部1个,底部1个)。我在下面分别为每个代码编写代码:

# boxplot of first group
boxplot(Top25[-1], main = "Top Performers Gene Expression Relative to 16S", ylab = "ddCt Values", xlab = "Biofilm Gene", cex.axis = 0.75)

# boxplot of second group 
boxplot(Bottom25 [-1], main = "Bottom Performers Biofilm Gene Expression Relative to 16S", ylab = "ddCt Values", xlab = "Biofilm Gene", cex.axis = 0.75)

对于我可能尝试的任何建议?我试图"融化"他们一起关注另一个ggplot2问题并得到一个错误说"没有找到对象熔化"。谢谢你的帮助!

2 个答案:

答案 0 :(得分:0)

这是一个例子。主要想法是使用add = TRUEboxplot添加到现有绘图中,并使用at指定boxplot的水平位置

#DATA
set.seed(42)
top = rnorm(40)
bottom = rnorm(40)

#Create Empty Plot
plot(1, 1, type = "n", xlim = c(0, 3), ylim = range(c(top, bottom)),
     ann = FALSE, xaxt = "n")

#Add boxplots to existing plot
boxplot(x = top, at = 1, add = TRUE)
boxplot(x = bottom, at = 2, add = TRUE)
axis(1, at = c(1, 2), labels = c("top", "bottom"))

enter image description here

答案 1 :(得分:0)

你可以这样做:

Top25 <- data.frame(gene=1:40, exp=rnorm(40, 2))
Bottom25 <- data.frame(gene=41:80, exp=rnorm(40, -2))

boxplot(list(Top25[, -1], Bottom25[, -1]), names=c("Top25", "Bottom25"))

enter image description here