我想为这些箱形图创建一个框架。如何将所有这两个箱形图放在R?
中的一个框或框中 x = c(1,3, 5, 8, 10)
y=c(2, 5, 6, 7, 9)
z = c(3, 5, 8, 10, 12)
par(mfrow=c(1, 3))
boxplot(x)
boxplot(y)
boxplot(z)
答案 0 :(得分:1)
一种选择是导出绘图并使用其他工具创建框架。我通常的工作流程是RStudio - >导出为PDF - >在Inkscape中编辑
如果您想以编程方式执行此类操作,则应该起作用:
x = c(1,3, 5, 8, 10)
y=c(2, 5, 6, 7, 9)
oldpar <- par(mfrow=c(1, 2))
boxplot(x)
boxplot(y)
# Modify the margin, so that the box is larger than the plots
par(mfrow=c(1,1), mar=c(1, 1, 1, 1))
box()
# Revert to original params
par(oldpar)
答案 1 :(得分:1)
这可以使用ggplot2
替代,并在构建所需的data.frame
时采取一些措施。
library(ggplot2)
library(reshape2)
x = c(1,3, 5, 8, 10)
y = c(2, 5, 6, 7, 9)
z = c(3, 5, 8, 10, 12)
data <- data.frame(x,y,z) #You may add as many variables as you like
DATA <- melt(data)
ggplot(data = DATA, aes(factor(1), value)) +
geom_boxplot() + facet_wrap(~variable,scales="free",ncol=8)+
theme(axis.text.x=element_blank(),
axis.title.x=element_blank(),
axis.title.y = element_blank())