GList chart side by side

I have 2 gList objects (mesh) that draw perfectly when I do

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

But I want them to be side by side in pdf. Sort of

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

But that will not work.

+2
source share
1 answer

To arrange the objects gridyou can use grid.layoutin the viewport. here is 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()

enter image description here

here getPlotis a function that returns 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)
}
+3
source

Source: https://habr.com/ru/post/1661810/


All Articles