how to add a long directional arrow after the text in xlab ggplot2?

1.2k views Asked by At

I would like to add an arrow after the text in xlab using ggplot2. Here is an example of a code below where I try to do it but adding dotted lines and signs but it is not very aesthetic.

ggplot(data=Q2, aes(x=month, y=dataQ)) +xlab("Mois     ------------------------------------------->") + ylab("Pr(mm)") +geom_bar(stat="identity", position = "dodge") + scale_x_discrete(limits=c("JAN", "FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"))+theme(plot.title = element_text(color="black", size=14, face="bold.italic"),axis.line = element_line(colour = "black", size = 1, linetype = "solid"),
                                                                                                                                                                                                                                                                                                                                              axis.text.x = element_text(face="bold", color=" black",size=11, angle=0),axis.text.y = element_text(face="bold", color="black",size=11, angle=90),axis.title.x = element_text(color="black", size=14, face="bold"),
                                                                                                                                                                                                                                                                                                                                              axis.title.y = element_text(color="black", size=14, face="bold") 
)

Here is the graph I get enter image description here

1

There are 1 answers

5
Dan On

You can use annotate and clip = "off", like below:

library(ggplot2)

ggplot() + 
  coord_cartesian(ylim = c(0, 1), xlim = c(0, 1), clip="off") +
  xlab("x label") +
  ylab("y label") +
  annotate("segment", 
           x = 0.6, xend = 0.9, y = -0.11, yend = -0.11,
           arrow=arrow(length=unit(0.3, "cm")))

Created on 2020-01-23 by the reprex package (v0.3.0)