使用箭头设定 ggplot 的 y 轴

4
有人知道如何水平更改y轴并添加箭头吗? 我想制作这样的图表。 以下是我用于制作此图表的代码。
ggplot(plot, aes(x=Worried.about.the.problems.caused.by.the.garbage., y=mean))
+ geom_bar(stat = "identity", position ="dodge", fill='#6699FF') + theme_minimal()+ ggtitle("Korea") + theme(plot.title = element_text(family = "serif", face = "bold", hjust = 0.5, size = 15, color = "black"))

enter image description here

enter image description here


3
这个问题得到了解答吗?[在ggplot2的坐标轴上添加彩色箭头(部分超出绘图区域)](https://dev59.com/oIXca4cB1Zd3GeqPJYSH) - A.Elsy
这看起来像是你可以使用注释(https://ggplot2.tidyverse.org/reference/annotate.html)。 - Wolfgang Arnold
请考虑接受给出的答案,这样这个问题就不会被标记为未回答了。谢谢。 - tjebo
1个回答

9
您可以使用theme调整图表中的元素,而不是使用annotate层来添加一个箭头到y轴。
library(ggplot2)

ggplot(mtcars, aes(x = cyl)) +
  geom_bar() +
  theme(axis.line.y = element_line(arrow = grid::arrow(length = unit(0.3, "cm"), 
                                                       ends = "both")))

关于“倾销更多”和“倾销更少”的轴标签,使用annotate可能是最简单的方法,但如果您真的想出于某种原因避免它,您可以在y轴标题中使用换行符,并在theme中调整标题的角度。
library(ggplot2)
ggplot(mtcars, aes(x = cyl)) +
  geom_bar() +
  theme(axis.line.y = element_line(arrow = grid::arrow(length = unit(0.3, "cm"), 
                                                       ends = "both")),
        axis.title.y = element_text(angle = 0)) +
  labs(y = "More Common\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nLess Common")

使用以下输出:enter image description here

很遗憾这个问题已经关闭了,这个答案比链接的答案更好。 - Mr.Rlover

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接