How to save inset viewport plots into .pdf file using grid and ggplot2 packages in R?

不羁的心 提交于 2019-12-23 05:32:12

问题


I created three overlapping plots in R using the diamonds data set using the viewports below. Is it possible to get them formatted the same way [overlapping] into a .pdf file?

vp <- viewport()

sbvp <- viewport(width=1,height=1,x=.5,y=.5) 

sbvp1 <- viewport(width=.4,height=.2,x=.28,y=.18)

sbvp2 <- viewport(width=.4,height=.2,x=.8,y=.72)

print(p0, vp=sbvp)  
print(p1, vp=sbvp1) 
print(p2, vp=sbvp2)  

Tried two separate ways [one below]. I understand ggsave wasn't working because it just works on the last plot, but am not even sure if using viewports in multiplot() is possible. It doesn't seem possible because of the column requirement, but this is what I ran:

 pdf("plot.pdf", width = 6.8, height = 4.7)
 multiplot(sbvp,sbvp1,sbvp2)
 dev.off()
 system('open "plot.pdf"')

Thanks,

来源:https://stackoverflow.com/questions/40145252/how-to-save-inset-viewport-plots-into-pdf-file-using-grid-and-ggplot2-packages

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