拼布导致不同宽度的图,尽管具有相同的区域

发布于 2025-02-06 12:21:40 字数 1084 浏览 1 评论 0原文

我正在用拼布组装11个地块。但是,奇怪的是,尽管在plot_layout()中定义了相同的区域,但右上图比其他图更窄。这是一个reprex:

create_plot <- function(x=NA){
  tibble(name = sample(letters[1:5], 50, replace=T),
               value = sample(letters[6:10], 50, replace=T)
               ) %>% 
  count(name, value) %>% 
  ggplot(aes(x=name, y=n, fill=value))+
  geom_col(show.legend = F)
}

areas <- c(  #top left bottom right
  area(1,1,1,4),    
  area(1,5,1,8),
  area(1,9,1,12),
  area(2,2,2,5),
  area(2,8,2,11),
  area(3,2,3,5),
  area(3,8,3,11),
  area(4,2,4,5),
  area(4,8,4,11),
  area(5,2,5,5),
  area(5,8,5,11)
)

plot(areas)

map(1:11, create_plot) %>% 
wrap_plots()+guide_area()+
  plot_layout(design = areas)

这是结果:

“代码的结果”

所有曲线均具有相同的宽度,除了右上方的宽度,这更窄。我还尝试使用带有相同结果的网格字符串:

areas <- "
  AAAABBBBCCCC
  #DDDD##EEEE#
  #FFFF##GGGG#
  #HHHH##IIII#
  #JJJJ##KKKK#
"

I'm assembling eleven plots with patchwork. But, weirdly, the top right plot is narrower than the others despite having the same area defined in plot_layout(). Here is a reprex:

create_plot <- function(x=NA){
  tibble(name = sample(letters[1:5], 50, replace=T),
               value = sample(letters[6:10], 50, replace=T)
               ) %>% 
  count(name, value) %>% 
  ggplot(aes(x=name, y=n, fill=value))+
  geom_col(show.legend = F)
}

areas <- c(  #top left bottom right
  area(1,1,1,4),    
  area(1,5,1,8),
  area(1,9,1,12),
  area(2,2,2,5),
  area(2,8,2,11),
  area(3,2,3,5),
  area(3,8,3,11),
  area(4,2,4,5),
  area(4,8,4,11),
  area(5,2,5,5),
  area(5,8,5,11)
)

plot(areas)

map(1:11, create_plot) %>% 
wrap_plots()+guide_area()+
  plot_layout(design = areas)

And here is the result:

result of the code

All plots have the same width, except the top right one, which is narrower. I also tried using the grid string with the same result:

areas <- "
  AAAABBBBCCCC
  #DDDD##EEEE#
  #FFFF##GGGG#
  #HHHH##IIII#
  #JJJJ##KKKK#
"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文