【发布时间】:2011-07-20 07:37:31
【问题描述】:
即使我在POSIXct 和geom_vline 的google 群组中找到了Hadley 的帖子,但我还是无法完成。例如,我有一个时间序列,并想为 1998 年、2005 年和 2010 年绘制一条垂直线。我尝试使用ggplot 和qplot 语法,但我还是看不到垂直线,或者垂直线是在第一个垂直网格处绘制的,整个系列有点奇怪地向右移动了。
gg <- ggplot(data=mydata,aes(y=somevalues,x=datefield,color=category)) +
layer(geom="line")
gg + geom_vline(xintercept=mydata$datefield[120],linetype=4)
# returns just the time series plot I had before,
# interestingly the legend contains dotted vertical lines
我的日期字段格式为“1993-07-01”,属于 Date 类。
【问题讨论】:
-
您可以添加几行数据框,以便我们尝试您的示例吗?
标签: r date ggplot2 time-series