在ggplot2中旋转条带文本

Jos*_*ant 5 r ggplot2 facet-wrap

我有一个很难搞清楚如何旋转strip.text的属性themeggplot2。我使用的是 R 版本 3.4.2 和 ggplot2 版本 2.2.1。

以下是 MWE 的数据。

> dput(dd)
structure(list(type = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 
4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), .Label = c("blossum", 
"happy", "rugged", "theatre"), class = "factor"), min = c(3, 
2, 4, 6, 3, 2, 4, 6, 3, 2, 4, 6, 3, 2, 4, 6, 3, 2, 4, 6), max = c(8, 
3, 7, 9, 8, 3, 7, 9, 8, 3, 7, 9, 8, 3, 7, 9, 8, 3, 7, 9), avg = c(5, 
1, 3, 3, 5, 1, 3, 3, 5, 1, 3, 3, 5, 1, 3, 3, 5, 1, 3, 3), y = c(1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 
5L, 5L, 5L)), .Names = c("type", "min", "max", "avg", "y"), row.names = c(NA, 
20L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)

现在,当使用该element_text()属性时,我可以为 着色strip.text但无法改变角度。我希望条带(方面)名称在左侧水平运行。这是代码:

ggplot(dd, aes(x = y, ymin = min, ymax = max, y = avg)) +
  facet_wrap(~ type, ncol = 1, strip.position = "left") +
  geom_ribbon(aes(x = y, ymin = min, ymax = max),
              color='black', fill='gray70') + coord_flip() +
  theme(strip.background = element_blank(),
        strip.text = element_text(angle=90, color='blue4'),
        axis.title.y = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.line.y = element_blank())
Run Code Online (Sandbox Code Playgroud)

这产生了这个图: 图的图片

然而,这不是我想要的,因为当角度在strip.text = element_blank(angle=90, color='blue4').

Jos*_*ant 11

没关系,我通过使用strip.text.y = element_text(angle = 180). 不知道为什么strip.text单独不起作用。


Jul*_*ien 11

strip.text.y.left现在使用。
添加angle = 0作为参数。

ggplot(dd, aes(x = y, ymin = min, ymax = max, y = avg)) +
  facet_wrap(~ type, ncol = 1, strip.position = "left") +
  geom_ribbon(aes(x = y, ymin = min, ymax = max),
              color='black', fill='gray70') + coord_flip() +
  theme(
    strip.background = element_blank(),
    strip.text.y.left = element_text(angle = 0, color = 'blue4'), #THE LINE THAT IS EDITED
    axis.title.y = element_blank(),
    axis.text.y = element_blank(),
    axis.ticks.y = element_blank(),
    axis.line.y = element_blank())
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

答案取自此评论