如何在垂直线上添加图例或标签?

时间:2016-10-06 21:31:13

标签: r ggplot2

time_centroid
[1] "2004-04-02 06:22:15 UTC"
> time_end
[1] "2004-04-03 18:15:00 UTC"
> time_max
[1] "2004-04-02 04:05:00 UTC"

ggplot(df,aes(y=precip,x=time))+
  geom_line()+
  geom_vline(xintercept = as.numeric(time_max))+
  geom_vline(xintercept = as.numeric(time_end))+
  geom_vline(xintercept = as.numeric(time_centroid))

enter image description here

  1. 如何在线条上添加个别标签(Max,End,Centroid)(可能在顶部停止与图形重叠)。
  2. OR。使用外部图例制作不同颜色的线条。
  3. 这是数据框:

    structure(list(time = structure(c(1080868500, 1080868800, 1080869100, 
    1080869400, 1080869700, 1080870000, 1080870300, 1080870600, 1080870900, 
    1080871200, 1080871500, 1080871800, 1080872100, 1080872400, 1080872700, 
    1080873000, 1080873300, 1080873600, 1080873900, 1080874200), class = c("POSIXct", 
    "POSIXt"), tzone = "UTC"), precip = c(1.76, 1.76, 1.21, 0.78, 
    0.59, 0.59, 0.62, 0.62, 0.81, 0.81, 1.14, 0.82, 0.87, 1.03, 0.98, 
    0.77, 0.77, 0.45, 0.55, 0.82)), .Names = c("time", "precip"), row.names = 236752:236771, class = "data.frame")
    

0 个答案:

没有答案