我作了一个发病时间的分布直方图,在限定x轴时间段时,设定与显示不一致,不知是什么原因。
数据如下。
d_pic = data.frame(case_time = as.POSIXct(c('2021-01-21 11:30:00',
'2021-01-21 11:30:00',
'2021-01-21 14:10:00',
'2021-01-21 14:30:00',
'2021-01-21 14:30:00',
'2021-01-21 14:30:00',
'2021-01-21 14:30:00',
'2021-01-21 15:00:00',
'2021-01-21 15:00:00',
'2021-01-21 15:00:00')
)
)
做图。
d_pic %>%
ggplot(aes(x = case_time)) +
geom_histogram(bins = 20, fill = 'gray80', color ='black') +
scale_x_datetime(limits = c(as.POSIXct('2021-01-21 16:00:00'),
as.POSIXct('2021-01-22 4:00:00')),
breaks = 'hours',
date_labels = '%m-%d %H:%M') +
theme_classic() +
coord_cartesian(expand = F) +
theme(axis.text.x = element_text(angle = 90),
axis.title = element_text(hjust = 1))
本来我是想因最早发病时间是11:30,x轴的开始时间设为8:00,我直接设2021-01-21 8:00:00,结果图上显示不对,设成'2021-01-21 16:00:00'才才8:00:00开始,好像差了8个小时,我认为是时区造成的,但加了tz参数也没用,不知道是什么原因,求大神帮助。