我相信这与 incidence 函数期望的参数有关。根据帮助?incidence第一个参数dates是:
日期向量,可以作为类的对象提供:
整数、数字、日期、POSIXct、POSIXlt 和字符。 (见说明
关于数字和字符格式)
不完全清楚outbreak 是否是,但大概是包含图像中数据的数据框(列列表)?错误消息可能来自提供数据框而不是日期向量。
如果您确实有一个数据框,例如示例:
date_use total_cases new_case
1 2020-03-01 168 25
2 2020-03-02 187 19
3 2020-03-03 200 13
4 2020-03-04 219 19
5 2020-03-05 252 33
6 2020-03-06 295 43
7 2020-03-07 336 41
8 2020-03-08 383 47
9 2020-03-09 470 87
10 2020-03-10 566 96
11 2020-03-11 698 132
您可以根据date_use 和new_case 创建日期向量:
my_dates <- rep(df$date_use, df$new_case)
table(my_dates)
my_dates
2020-03-01 2020-03-02 2020-03-03 2020-03-04 2020-03-05 2020-03-06 2020-03-07 2020-03-08 2020-03-09
25 19 13 19 33 43 41 47 87
2020-03-10 2020-03-11
96 132
那么你可以使用incidence如下创建关联对象:
i <- incidence(my_dates, interval = 1)
i
<incidence object>
[555 cases from days 2020-03-01 to 2020-03-11]
$counts: matrix with 11 rows and 1 columns
$n: 555 cases in total
$dates: 11 dates marking the left-side of bins
$interval: 1 day
$timespan: 11 days
$cumulative: FALSE
然后绘制:
plot(i, border = "white")