【发布时间】:2021-10-25 16:41:37
【问题描述】:
我正在制作一个相当复杂的条形图,并在其中添加了一条额外的帕累托线。 通常我的条形图可以正常工作 - 也可以使用堆叠条顶部的 geom_text() 标签。 但现在我似乎无法让它工作。 geom_bar() 的 geom_text() 在每个柱上的顺序错误(从上到下),我不知道为什么。这是(部分)我的代码:
ggplot() +
theme_mso() +
geom_bar(data = uth.sum, aes(x = reorder(dpsd_ny, -n), y = n, fill = alvor), stat = "identity") +
geom_text(data = uth.sum, aes(x = reorder(dpsd_ny, -n), y = n, label = n), position = position_stack(vjust = .5)) +
scale_fill_manual(values = col) +
geom_point(data = uth.sum2, aes(x = dpsd_ny, y = akkumuleret)) +
geom_line(data = uth.sum2, aes(x = dpsd_ny, y = akkumuleret, group = 1), stat = "identity") +
scale_y_continuous(sec.axis = sec_axis(~(./total_value)*100, name = "Procent")) +
geom_text(data = uth.sum2, aes(x = dpsd_ny, y = akkumuleret, label = procent), position = position_stack(vjust= 1.08)) +
....等等。希望这是有道理的,并且有人可以提供帮助!
【问题讨论】:
-
为了帮助我们提供帮助,您是否介意提供 a minimal reproducible example 包括您的数据的 sn-p 以测试您的代码。
-
...但您可以尝试将组 aes(即
group = alvor)添加到 geom_text。 -
group = alvor 工作!!!不知道为什么我自己没有尝试...非常感谢 stefan!