最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

r - Combine three plots keeping same width with patchwork - Stack Overflow

programmeradmin2浏览0评论

I am trying to combine three plots, and I would like to have one plot on top and two in a second row one next to the other. All plots should have same height and width. I am using patchwork package. However, with the solution I found, the two bottom plots still seem to have different width. Any suggestion on how to proceed? Below you can find a reproducible example that shows what I mean:

library(tidyverse)
library(patchwork)

data("iris")

plot1 <- iris %>% 
  ggplot(aes(x = Species, y = Sepal.Length)) +
  geom_point()

design <- "#AA#
           BBCC"

plot_comb <- plot1 + plot1 + plot1 + 
  plot_annotation(tag_levels = "A") + plot_layout(design = design) & 
  theme(plot.tag = element_text(face = "bold"))

plot_comb

Thank you in advance!

I am trying to combine three plots, and I would like to have one plot on top and two in a second row one next to the other. All plots should have same height and width. I am using patchwork package. However, with the solution I found, the two bottom plots still seem to have different width. Any suggestion on how to proceed? Below you can find a reproducible example that shows what I mean:

library(tidyverse)
library(patchwork)

data("iris")

plot1 <- iris %>% 
  ggplot(aes(x = Species, y = Sepal.Length)) +
  geom_point()

design <- "#AA#
           BBCC"

plot_comb <- plot1 + plot1 + plot1 + 
  plot_annotation(tag_levels = "A") + plot_layout(design = design) & 
  theme(plot.tag = element_text(face = "bold"))

plot_comb

Thank you in advance!

Share Improve this question asked Mar 19 at 14:57 kriskris 1657 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I admit to not knowing exactly why this is necessary for three identical plots, I find the use of free(.) helpful when I need to strong-arm some alignment attempts (that are normally very welcome).

Your code for me produces:

plot_comb <- free(plot1) + free(plot1) + free(plot1) + 
  plot_annotation(tag_levels = "A") + plot_layout(design = design) & 
  theme(plot.tag = element_text(face = "bold"))
plot_comb

发布评论

评论列表(0)

  1. 暂无评论