我知道当你使用par( fig=c( ... ), new=T )
,您可以创建插图。但是,我想知道是否可以使用 ggplot2 库来创建“插图”图。
更新1:我尝试使用par()
用ggplot2,但它不起作用。
更新2:我找到了一个可行的解决方案ggplot2 谷歌群组 using grid::viewport()
.
第 8.4 条the book解释了如何执行此操作。诀窍是使用grid
包的viewport
s.
#Any old plot
a_plot <- ggplot(cars, aes(speed, dist)) + geom_line()
#A viewport taking up a fraction of the plot area
vp <- viewport(width = 0.4, height = 0.4, x = 0.8, y = 0.2)
#Just draw the plot twice
png("test.png")
print(a_plot)
print(a_plot, vp = vp)
dev.off()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)