变量
first_name
,
last_name
和
symptom_onset
表示个人的名称以及他们出现症状的日期和时间。通过使用as.date()函数,我可以使用此代码轻松地创建一个epicurve:
finding_nemo$symptom_onset <- as.Date(finding_nemo$symptom_onset)
ggplot(data=finding_nemo, aes(x=symptom_onset))+
geom_histogram(fill="#197C67")+
geom_text(stat="count", aes(label=..count..), vjust=-1)+
labs(title="EpiCurve for Sick Fish at Nemo's Picnic", x="Symptom Onset", y="Number of Cases")+
scale_x_date(limits=as.Date(c("2023-05-15", "2023-05-25")))+ #This line of code specifies the date range that we want to see in the epicurve
theme_minimal()
产生的图表看起来像这样:,但是,as.date()函数从时间戳上脱落,因此上皮(直方图)仅表示日期,我想具有时间的粒度。
所以,我想做的就是能够用X轴显示日期和时间的X轴,而代表疾病的条形在特定时间段内每2小时计算每2小时。任何指导都将不胜感激!
ggsurveillance
lubridate::floor_date()
希望这帮助