0

我有几个ggplots组合使用的图表patchwork。我制作了一个ggplot仅由 y 轴组成的。我现在正在努力将这个 y 轴 ggplot 移近 ggplots。有任何想法吗?

在此处输入图像描述

这是打包工作代码:

y_axis + decreasers_p+late_bloomers_p + o2_lovers_p + solo_riders_p + plot_layout(widths = c(1, 10), 
                                                                        guides = "collect",
                                                                        design = 
                                                                        "12
                                                                         13
                                                                         14
                                                                         15") 


这是一些ggplot代码:

solo_riders_p <- ggplot(solo_riders, aes(x=days_incubated, y=emission))+
  geom_point(aes(shape=compound, size=compound, fill=compound)) +
  scale_shape_manual(values=c(21, 25))+
  scale_size_manual(values=c(2.8, 2.5))+
  scale_fill_manual(values=c("black", "grey"))+
  labs(fill = "Compound", shape = "Compound", size = "Compound", 
       x = "Incubation time (days)", 
       y = "BVOC emission (nmol g-1 loi soil h-1)", 
       title = "solo_riders") +
  theme_bw() +
  facet_wrap(vars(jar), scales = "free_y")

y_axis <- ggplot(data.frame(l = decreasers_p$labels$y, x = 1, y = 1)) +
  geom_text(aes(x, y, label = l), angle = 90) + 
  theme_void() +
  coord_cartesian(clip = "off")
4

1 回答 1

2

这是使用 ggplot2 的主题系统生成适当的 y 轴标题作为 grob 的解决方案,然后您可以将其拼凑到其他标题上。如果您使用的自定义主题不是全局的,请将 替换为theme_get()您的主题。

用虚拟图显示,因为我没有数据来重现您的确切用例。

library(ggplot2)
library(patchwork)

plt <- ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  scale_y_continuous(name = "")

yaxis <- calc_element("axis.title.y.left", theme_get())
yaxis <- element_grob(yaxis, label = "mpg")

plt + plt + yaxis +
  plot_layout(
    design = c("31\n32"),
    widths = c(0.01, 1)
  )

reprex 包(v0.3.0)于 2020 年 12 月 17 日创建

于 2020-12-17T11:59:49.283 回答