gpt4 book ai didi

在ggplot2中旋转 strip 文本

转载 作者:行者123 更新时间:2023-12-04 10:48:31 26 4
gpt4 key购买 nike

我很难弄清楚如何旋转 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com