简体   繁体   English

带有一个绘图facet_grid的GGplot和gridExtra-如何完美匹配比例尺?

[英]GGplot and gridExtra with one plot facet_grid - how to have perfectly fit scales?

I am using grid.arrange() to put two plots in one. 我正在使用grid.arrange()将两个图grid.arrange() However, one of the plots is created using facet_grid and thus has additional text on its right side. 但是,其中一个图是使用facet_grid创建的,因此在其右侧具有其他文本。 Therefore the scales do not perfectly match (see picture below) 因此,秤并不完全匹配(请参见下图)

标签的图片不完全重叠

I want the scales to be perfectly above or underneath each other, 10 above 10, 9 above 9 and so on. 我希望比例尺完全在彼此之上或之下,10在10之上,9在9之上,依此类推。 Can anybody help on how to achieve this? 任何人都可以帮助实现这一目标吗? Should I remove the text from the facet_grid? 我应该从facet_grid删除文本吗? If so, how can I do so? 如果是这样,我该怎么办?

EDIT Exampe for illustrating my issue 编辑举例说明我的问题

g1 <- ggplot() +
  geom_point(data = neu1, aes(x = AGE, y = costs,
                               colour = Type, shape = Type),
             size = 3)+
  scale_x_continuous(limits = c(-1,10), breaks = seq(0,10,1))+
  ylab("Costs")

g2 <- ggplot() +
  geom_point(data = neu1, aes(x = AGE, y = costs,
                              colour = Type, shape = Type),
             size = 3)+
  scale_x_continuous(limits = c(-1,10), breaks = seq(0,10,1))+
  ylab("Costs")+
  facet_grid(Type ~.)
grid.arrange(g1,g2, nrow = 2)

This gives the following output as to be seen in the picture above, for this example two plots do not make too much sense, it is just for illustration. 如上图所示,这提供了以下输出,对于此示例,两个图没有太大的意义,仅用于说明。

As you can see, the gridlines for each number are not on top of each other, for example AGE 10 on the upper plot is further to the right side than on the lower plot. 如您所见,每个数字的网格线不是彼此重叠的,例如,上图中的AGE 10比下图中的更靠近右侧。 Thank you once more to all! 再次谢谢大家!

You should be able to remove the facet labels with "strip" arguments in theme(). 您应该能够在theme()中使用“ strip”参数删除构面标签。

p + theme(strip.text = element_blank(), 
    strip.background = element_blank())

Where p is the the facet plot from the original post. 其中p是原始帖子的构面图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM