简体   繁体   English

如何使用注释在ggplot2中绘制箭头

[英]how to draw arrow in ggplot2 with annotation

I am creating a ggplot chart where I need to put some annotation. 我正在创建一个ggplot图表,我需要在其中添加一些注释。 I can do that but the text is not really pointing exactly the date that I like annotate. 我可以这样做,但文本并没有真正指出我喜欢注释的日期。 Is there a way to draw an arrow to axix where I like create the annotation. 有没有办法在axix中绘制箭头,我喜欢创建注释。

I have this: 我有这个:

   ggplot(df, aes(Date, CPU)) + geom_point() + 
       annotate("text", x = as.POSIXct(c("2013-03-11 23:00:00")), 
                y = 90, label = "problem 1", angle=90, size=5, 
                colour='black', face="bold")

just so anyone might have the same question or query, here is what I did: 所以任何人都可能有相同的问题或疑问,这就是我所做的:

library(ggplot2)
library(grid)

ggplot(df, aes(Date, CPU)) + geom_point() + 
       annotate("text", x = as.POSIXct(c("2013-03-11 23:00:00")), 
                y = 90, label = "problem 1", angle=90, size=5, 
                colour='black', face="bold")
             +    geom_segment(aes(x = as.POSIXct(c("2013-03-11 09:00:00")), y = -30, xend = as.POSIXct(c("2013-03-11 09:00:00")), yend = 0), colour='#CC00FF', size=1,arrow = arrow(length = unit(0.5, "cm")))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM