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()

 

posted @ 2015-08-26 19:43  yangk  阅读(6514)  评论(0编辑  收藏  举报