1

edit

How can I change axis lines to arrows on my plot?

Here a sample plot where both axis should have arrows at the end (plot from user chemdork123's answer).

ggplot(mtcars, aes(mpg,disp)) + geom_point() + theme_minimal() 
tjebo
  • 21,977
  • 7
  • 58
  • 94
  • 3
    Hi and welcome to SO! Please, be sure to include your dataset when you also include code in order for everyone to replicate your question. Sharing a smaller-sized dataset can be done via pasting the output of `dput(your.data.frame)` into your question as code. Alternatively, you can always pose your question using one of the built-in datasets of R, such as `mtcars`, `iris`, etc. – chemdork123 Jun 29 '20 at 12:37

1 Answers1

3

To represent the x or y axis as an arrow, you can access the theme() elements for those objects. This is a good place to go for information on the theme objects you can modify.

In this case, you'll want to access axis.line (for all axes) or axis.line.x or axis.line.y to access either x or y axes individually. The arguments must be changed via calling element_line() and then within element_line() there is an argument for arrow= where you can use the arrow() function to change the look of the arrows.

Here's an example using mtcars:

ggplot(mtcars, aes(mpg,disp)) + geom_point() + theme_minimal() +
  theme(axis.line = element_line(arrow = arrow(type='closed', length = unit(10,'pt'))))

enter image description here

chemdork123
  • 12,369
  • 2
  • 16
  • 32