从grid.arrange删除边框 [英] remove the borders from grid.arrange

查看:256
本文介绍了从grid.arrange删除边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gridExtra包grid.arrange函数来组合多重ggplot图.

I am combining multip ggplot graphs using gridExtra package grid.arrange function.

我这样做:

p1<-ggplot(x, aes(Date, Value)) + geom_line()
p2<-ggplot(y, aes(Date, Score)) + geom_point()
grid.arrange(p1, p2,  main=textGrob("Head Line", gp=gpar(cex=1.5, fontface="bold", col="#990000")), ncol = 1, clip=TRUE)

此命令在p1和p2之间放置边框.我找不到有关删除grid.arrange中的边框的任何信息.可以删除边框吗?

this command puts border between p1 and p2. I couldn't find any info on removeing the borders in grid.arrange. Is it possible to remove the borders?

推荐答案

gridExtra在图之间不添加任何其他边框.您所看到的只是每个图周围的边界.也就是说,在p1的底部有一个边界,在p2的顶部有一个边界.将两者放在一起,看起来两者之间似乎还有额外的空间.

gridExtra doesn't put any additional border between the plots. All you are seeing are the borders that already surround each plot. That is, there is a border at the bottom of p1 and a border at the top of p2. Put the two together, and it might look like there is additional space between the two.

要删除或调整每个图的边框,请使用theme函数中的plot.margin元素.以下内容删除了p1的底部边距和p2的顶部边距.

To remove or to adjust each plot's borders, use the plot.margin element in the theme function. The following removes the bottom margin of p1 and the top margin of p2.

library(ggplot2)
library(gridExtra)

p1<-ggplot(data.frame(x = 1:10, y = 1:10), aes(x, y)) + geom_line() +
      theme(plot.margin = unit(c(1,1,0,1), "lines"))

p2<-ggplot(data.frame(x = 1:10, y = 1:10), aes(x, y)) + geom_point() +
   theme(plot.margin = unit(c(0,1,1,1), "lines"))

grid.arrange(p1, p2,  top=textGrob("Head Line", 
     gp=gpar(cex=1.5, fontface="bold", col="#990000")), ncol = 1, clip=TRUE)

编辑(2015年7月16日):在gridExtra> = 2.0.0的情况下,main参数已重命名为top.

Edit (16/07/2015): with gridExtra >= 2.0.0, the main parameter has been renamed top.

这篇关于从grid.arrange删除边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆