相关疑难解决方法(0)

如何将一个垂直geom_vline转换为类日期的x轴?

即使我发现哈德利对谷歌的论坛中发帖POSIXctgeom_vline,我无法完成它.我有一个时间序列,并希望绘制1998年,2005年和2010年的垂直线.我尝试使用ggplotqplot语法,但我仍然看不到垂直线,或者在第一个垂直网格上绘制垂直线,整个系列在右边有点奇怪地移动.

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
Run Code Online (Sandbox Code Playgroud)

我的日期字段格式为"1993-07-01",属于班级Date.

r date time-series ggplot2

93
推荐指数
3
解决办法
6万
查看次数

ggplot2:如何在时间x轴上向多条垂直线(geom_vlines)添加文本?

请看下面的例子

library(dplyr)
library(lubridate)
library(ggplot2)
data <- data_frame(time = c(ymd(20160201),
                            ymd(20160202),
                            ymd(20160203),
                            ymd(20160201),
                            ymd(20160202)),
                            value = c(1,1,1,2,2), 
                            group = c('A','A','B','B','B'))

events <- data_frame(time = c(ymd(20160201), 
                              ymd(20160202)),
                     text = c('who let the dogs out?',
                              'who? who? who?'))

ggplot(data, aes(x = time, y = value, group = group, color = group)) + 
  geom_line(size = 2 ) +
  geom_vline(data = events, aes(xintercept = as.numeric(time)))  

> data
# A tibble: 5 × 3
        time value group
      <date> <dbl> <chr>
1 2016-02-01     1     A
2 2016-02-02 …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

5
推荐指数
1
解决办法
9630
查看次数

标签 统计

ggplot2 ×2

r ×2

date ×1

time-series ×1