带箭头的ggplot y轴

Seh*_*ang 2 r ggplot2 yaxis

有谁知道如何水平更改 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"))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在此输入图像描述

小智 5

您可以使用theme向 y 轴添加箭头而不是使用annotate图层来调整图中的元素。

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")))
Run Code Online (Sandbox Code Playgroud)

至于“倾销更多”和“倾销更少”的轴标签,使用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")
Run Code Online (Sandbox Code Playgroud)

随着输出: 在此处输入图片说明