In ggplot2_2.2.1您可以使用以下命令将面板条移动为 y 轴标签strip.position
论证中facet_wrap
。使用此方法,您不会同时拥有条带标签和不同的 y 轴标签,但这可能并不理想。
将条带标签放置在 y 轴(“左”)上后,您可以通过给定一个命名向量来更改标签labeller
用作查找表。
条带标签可以通过以下方式移到 y 轴之外strip.placement
in theme
.
删除条形背景和 y 轴标签,以获得具有两个窗格和不同 y 轴标签的最终图形。
ggplot(my.df, aes(x = time, y = value) ) +
geom_line( aes(color = variable) ) +
facet_wrap(~Unit, scales = "free_y", nrow = 2,
strip.position = "left",
labeller = as_labeller(c(A = "Currents (A)", V = "Voltage (V)") ) ) +
ylab(NULL) +
theme(strip.background = element_blank(),
strip.placement = "outside")
Removing the strip from the top makes the two panes pretty close together. To change the spacing you can add, e.g., panel.margin = unit(1, "lines")
to theme
.