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

1 回答 1

17

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")))
于 2013-06-10T21:58:26.980 回答