Plot gList side by side

你。 提交于 2019-12-12 21:15:02

问题


I have 2 gList objects (grid) that plots fine when I do

grid.draw(plot1)
grid.draw(plot2)

But I want these to be side by side in a pdf. Something like

pdf(test.pdf)
par(mfrow=c(1,2))
plot(1:10)
plot(10:1)
dev.off

But this doesn't work.


回答1:


To arrange grid objects , you can use grid.layout within a viewport. here an example.

pushViewport(plotViewport(layout=grid.layout(1, 2),gp=gpar(cex=2)))
pushViewport(plotViewport(layout.pos.col=1))
  grid.draw(getPlot())
popViewport()
pushViewport(plotViewport(layout.pos.col=2, clip="on"))
  grid.draw(getPlot(col.fill='black',col.text='red',text='Rouge',x=0))
popViewport()
popViewport()

here getPlot is a function that retuen a gList;

getPlot <- function(col.fill="red",col.text='black',text="Noir",x=1){
  rect1 <- rectGrob(gp=gpar(fill=col.fill))
  text1 <- textGrob(text,gp=gpar(col=col.text))
  text2 <- textGrob("&", x=x,gp=gpar(col=col.text))
  gList(rect1,text1,text2)
}


来源:https://stackoverflow.com/questions/15521671/plot-glist-side-by-side

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!