R语言画图布局摆放(layout)

require(ggplot2)
require(Cairo)
require(grid)
p = ggplot(iris,aes(x = Species,y = Sepal.Length,colour = Species))
p+geom_point()
a = p+geom_point()
b = qplot(Sepal.Length,Petal.Length,data=iris,geom="point",colour = Species)
c = qplot(Species,Sepal.Width,data=iris,geom="boxplot",fill = Species)
#创建新的画图页面
grid.newpage()
pushViewport(viewport(layout = grid.layout(2,2)))
vplayout = function(x,y)viewport(layout.pos.row = x,layout.pos.col = y)
print(a,vp = vplayout(1,1:2))
print(b,vp = vplayout(2,1))
print(c,vp = vplayout(2,2))
ggsave("test_layout.pdf",width = 8,height = 6)
dev.off()

R语言画图布局摆放(layout)_第1张图片

 

转载于:https://www.cnblogs.com/yangk/p/4761470.html

你可能感兴趣的:(R语言画图布局摆放(layout))