[英]Creating frame for several box plots
我想為這些箱形圖創建框架。 如何將所有這兩個箱形圖放在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)
一種選擇是導出繪圖並使用另一種工具創建框架。 我通常的工作流程是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)
這是使用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())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.