我怀疑这是您想要的,实际上使用标准graphics
包中的绘图功能并不是很复杂。这些组被绘制为 4 个单独的面板,但在外部边缘绘制了一个共享的 y 轴和标题,它看起来像一个单独的图。
# Faking the data, since you didn't provide any
Gene <- data.frame(matrix(rweibull(100*4, 1), 100))
names(Gene) <- paste0("Ind", 1:4)
Gene <- rep(list(Gene), 4)
# Setup the panels
layout(t(1:4))
par(oma=c(2, 4, 4, 0), mar=rep(1, 4), cex=1)
# `mar` controls the space around each boxplot group
# Calculating the range so that the panels are comparable
my.ylim <- c(min(sapply(Gene, min)), max(sapply(Gene, max)))
# Plot all the boxes
for(i in 1:length(Gene)){
boxplot(Gene[[i]], ylim=my.ylim, axes=FALSE)
mtext(paste("Gene", i), 1, 0)
if(i == 1){
axis(2, las=1)
mtext("Expression or what you have", 2, 3)
}
}
title("Look at all my genes!", outer=TRUE)
顺便说一句,我建议将您的数据框存储在一个列表中,而不是通过将它们命名为“Gene1”、“Gene2”、“Gene3”和“Gene4”来模仿一个列表。以这种方式自动化要容易得多。如果您仍想将它们存储为单独的变量,请替换Gene[[i]]
withget(paste0("Gene", i))
和my.ylim <- ...
withmin(c(min(Gene1), min(Gene2) ...
等。