3

Is there anyone who knows how to change the y-axis horizontally and add the arrow? I want to make graph like this. This is the code that I used for making this graph.

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

Sehee Yang
  • 41
  • 2
  • 4
  • 3
    Does this answer your question? [Add colored arrow to axis of ggplot2 (partially outside plot region)](https://stackoverflow.com/questions/27140058/add-colored-arrow-to-axis-of-ggplot2-partially-outside-plot-region) – A.Elsy Feb 07 '20 at 10:53
  • This looks like you could use annotations (https://ggplot2.tidyverse.org/reference/annotate.html) – Wolfgang Arnold Feb 07 '20 at 13:07
  • Please consider accepting the given answer, so that this question is not flagged as unanswered anymore. Thanks – tjebo Feb 09 '20 at 12:11

1 Answers1

8

You can adjust the elements in the plot using theme to add an arrow to the y-axis instead of using an annotate layer.

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")))

As for the axis labels for "dumping more" and "dumping less", using annotate is probably easiest, but if you really wanted to avoid it for some reason, you could use line breaks in your y-axis title and adjust the angle of the title in 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")

With the output: enter image description here

krfurlong
  • 867
  • 6
  • 17