在同一工作区中显示绘图

时间:2018-04-13 15:18:56

标签: r

我试图在第一行水平显示第一个箱图,第二行显示两个散点图,最后在第三行显示两个垂直箱图。我怎样才能更好地编写代码,以便按照我想要的方式显示图表?

layout(matrix(c(1, 1,
                2, 3, 
                4, 5, nrow=2, byrow=TRUE))
layout.show(n=5)

boxplot(calories, data = cereal, horizontal = TRUE,  main='Boxplot of Calories of Cereals')
plot(calories, fat, main='Calories vs Fat of Cereals', xlab="Calories", ylab="Fat", las=1)
plot(calories, protein, main='Calories vs Protein of Cereals', xlab="Calories", ylab="Protein", las=1)
boxplot(fat, data = cereal, las=1, xlab="Fat", main='Boxplot of Fat of Cereals')
boxplot(protein, data = cereal, las=1, xlab="Protein", main='Boxplot of Protein of Cereals')

1 个答案:

答案 0 :(得分:0)

检查layaut这应该有用的设计

layout(matrix(c(1,1,2,3,4,5), nrow=3,ncol=2, byrow = TRUE))
par(mar=c(4,4,3,3))
set.seed(1)
cereal = data.frame(calories = rnorm(15,378,10), fat = rnorm(15,0.9,0.02), protein = rnorm(15,7,1.3))
attach(cereal)

boxplot(calories, data = cereal, horizontal = TRUE,  main='Boxplot of Calories of Cereals')
plot(calories, fat, main='Calories vs Fat of Cereals', xlab="Calories", ylab="Fat", las=1)
plot(calories, protein, main='Calories vs Protein of Cereals', xlab="Calories", ylab="Protein", las=1)
par(mgp=c(1,1,0))
boxplot(fat, data = cereal, las=1, xlab="Fat", main='Boxplot of Fat of Cereals')
boxplot(protein, data = cereal, las=1, xlab="Protein", main='Boxplot of Protein of Cereals')

enter image description here