在ggplot2中旋转 strip 文本

标签 r ggplot2 facet-wrap

我很难弄清楚如何旋转 strip.text theme 中的属性来自 ggplot2 .我使用的是 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")

现在使用 element_text() 时属性,我可以为 strip.text 着色但无法改变角度。我希望 strip (方面)名称在左侧水平运行。这是代码:
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())

这产生了这个图:
picture of the graph

然而,这不是我想要的,因为在 strip.text = element_blank(angle=90, color='blue4') 中改变角度时它们没有区别。 .

最佳答案

没关系我用 strip.text.y = element_text(angle = 180) 弄明白了.不知道为什么 strip.text单独是行不通的。

关于在ggplot2中旋转 strip 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48892826/

相关文章:

r - 如何在R中均匀地绘制geom_text?

r - R 中的 HDBSCAN 可视化应用文本标签而不是数字

r - 增加 y 轴刻度标签 ggplot2 上的间距

r - 如何访问隐藏得很好的隐藏功能

r - 有什么办法延长图例中的界限吗?

r - FUN(X[[i]], ...) 错误 : object not found when adding geom_text with facet

r - 使用facet_wrap()时添加单独的X和Y轴标签

R Shiny 的 ggplot facet_wrap 取决于选择输入

r - 从数组中提取满足 R 中条件的索引

c - 是否可以在下载时安装 R 包的外部依赖项