更改情节尺寸GGPLOT2(Change plot dimensions in ggplot2)

2019-10-18 06:07发布

我想创建一个单一的PDF文件,并用包把几个地块在它ggplot2 。 不过,我需要减少的一个特定情节的宽度,在所有。 下面是代码:

invisible(pdf("foo.pdf"))
foo <- data.frame(x=rnorm(100), y=rnorm(100), class=factor(sample(2,1000,T)))
ggplot(foo, aes(x=x,y=y))+geom_point() # first plot

# For next plot I want to reduce the width
ggplot(foo, aes(x=class,y=y)) + geom_boxplot()
invisible(dev.off())

怎么做?

Answer 1:

您可以在视口中打印小于整个页面,

library(grid) 
grid.rect(width=unit(0.8, "npc"), gp=gpar(lty=2))
print(qplot(1,1), vp=viewport(width=unit(0.8, "npc")))


文章来源: Change plot dimensions in ggplot2
标签: r ggplot2