如何在xlab ggplot2中的文本之后添加长方向箭头?

问题描述 投票:0回答:1

我想使用ggplot2在xlab中的文本后面添加一个箭头。这是下面的代码示例,我尝试执行此操作,但是添加了虚线和符号,但不是很美观。

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

这是我得到的图enter image description here

r ggplot2 axis-labels xlabs
1个回答
1
投票

您可以使用annotateclip = "off",如下所示:

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

“”

reprex package(v0.3.0)在2020年1月23日创建

© www.soinside.com 2019 - 2024. All rights reserved.