我想把几个地块连在一起。 我已经找到了如何使用鸡蛋对齐地块的解决方案:ggarrange。 这很好地照顾了主要情节。 但我想让所有情节的y.axis标题也一致。 我不能通过使用ggplot选项的通常建议来做到这一点,因为每次运行我的脚本时,数字的范围会有所不同,并且无法提供固定范围,因此轴标题的位置会发生变化。 我知道可以将图例和位置分开放在一个单独的网格中,我想知道我们是否可以对轴做同样的事情?
我在这里创建了一个简单的示例代码。
# example created to explain my problem gdf <- data.frame(a = runif(10, 0, 1), b = runif(10, 100, 1000), c= runif(10, 10000,100000), d= runif(10, 100000,1000000)) p1 <- ggplot(gdf, aes(a, b)) + geom_point() + ylab ("first") p2 <- ggplot(gdf, aes(a, c)) + geom_point() + ylab ("Second") p3 <- ggplot(gdf, aes(a, d)) + geom_point() + ylab ("third" ) egg::ggarrange(p1, p2, p3, ncol= 1, nrow = 3, heights=c(1, 1, 1))
I am trying to attach several plots together. I have found the solution on how to align the plots using egg:ggarrange. This nicely takes care of main plots. But I would like to have the y.axis title of all plots to be aligned also. And I cannot do it through the usual suggestion of working with ggplot options, since everytime I run my scripts the range of the numbers would be different and cannot come up with a fixed range, therefore the location of the axis title change. I know it is possible to separate the legend and place in a separate grid, I was wondering if we could do the same thing with the axis?
I have created a simple sample code here.
# example created to explain my problem gdf <- data.frame(a = runif(10, 0, 1), b = runif(10, 100, 1000), c= runif(10, 10000,100000), d= runif(10, 100000,1000000)) p1 <- ggplot(gdf, aes(a, b)) + geom_point() + ylab ("first") p2 <- ggplot(gdf, aes(a, c)) + geom_point() + ylab ("Second") p3 <- ggplot(gdf, aes(a, d)) + geom_point() + ylab ("third" ) egg::ggarrange(p1, p2, p3, ncol= 1, nrow = 3, heights=c(1, 1, 1))最满意答案
你可以使用cowplot::plot_grid ,它有一个align参数:
cowplot::plot_grid(p1, p2, p3, align = "v", ncol = 1)
You can use cowplot::plot_grid which has an align argument :
cowplot::plot_grid(p1, p2, p3, align = "v", ncol = 1)更多推荐
发布评论