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

7

我正在创建一个ggplot图表,需要添加一些注释。我可以做到这一点,但是文本并没有真正指向我想要注释的确切日期。有没有办法在我希望创建注释的轴上绘制箭头。

我有以下代码:

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

2
Luke,...使用网格。 - IRTFM
1个回答

16

为了让任何人都能有同样的问题或疑问,这是我所做的:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接