【发布时间】:2021-03-29 00:46:57
【问题描述】:
我正在尝试使用 FL_Actions 和该线的点数据绘制带有 geom_hline 的时间序列。到目前为止,我已经能够添加 geom_hline,但是在添加带有 FL_Action 标签的 geom_point 时遇到问题,其中 1 等于关闭策略,2 等于开放策略。我正在使用这个数据集(参见下面的示例):
# A tibble: 22 x 10
Date Date2 Date3 FLORIDA FLday MICHIGAN MIday FL_Actions MI_Actions realdate
<chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <date>
1 3/6/20 3/6/20 3/6/20 3 0 0 0 NA NA 2020-03-06
2 3/7/20 3/7/20 3/7/20 7 4 0 0 NA NA 2020-03-07
3 3/8/20 3/8/20 3/8/20 10 3 0 0 NA NA 2020-03-08
4 3/9/20 3/9/20 3/9/20 13 3 0 0 1 NA 2020-03-09
5 3/10/20 3/10/20 3/10/20 15 2 0 0 NA 1 2020-03-10
6 3/11/20 3/11/20 3/11/20 24 9 2 2 1 NA 2020-03-11
7 3/12/20 3/12/20 3/12/20 30 6 3 1 NA NA 2020-03-12
8 3/13/20 3/13/20 3/13/20 45 15 22 19 NA NA 2020-03-13
9 3/14/20 3/14/20 3/14/20 64 19 35 13 NA NA 2020-03-14
10 3/15/20 3/15/20 3/15/20 100 36 45 10 NA NA 2020-03-15
# … with 12 more rows
这是我当前的代码:
ggplot(MI_FL_Data, aes(realdate, FLday))+
geom_line() +
geom_hline(aes(yintercept = 15000), data=MI_FL_Data, linetype=2) +
geom_hline(aes(yintercept=17000), data=MI_FL_Data, linetype=4) +
geom_point(aes(col=8, 15000)) +
geom_point(aes(col=8,17000)) +
labs(x=NULL, y="Number of Reported Daily COVID Cases", title="State of Florida") +
theme_classic()
但是,我不断收到一条错误消息:错误:输入无效:date_trans 仅适用于 Date 类的对象。
我想我需要添加 realdate(我使用 library(lubridate) 创建 realdate 变量),但只希望编码为 1 的日期在一个 geom_hline 上,而那些编码为 2 的日期在另一个 geom_hline 上。这看起来像:
geom_point(aes(realdate, col=8 if.1) yintercept 17000)
或者类似的?
【问题讨论】: