我有一个数据帧df为
Time Day
2:03:00 AM Wed
2:02:00 AM Wed
1:56:00 AM Mon
1:54:00 AM Tue
1:53:00 AM Mon
1:51:00 AM Sun
1:51:00 AM Sun
1:50:00 AM Sun
1:48:00 AM Sun
我想绘制一个图表,我可以在12到凌晨2点,凌晨2点到凌晨4点等范围内绘制时间,以此类推。
请帮忙。
答案 0 :(得分:1)
认为这基本上就是你的目标
data <- data.frame(Time=c("2:03:00 AM", "2:02:00 AM", "1:56:00 AM", "1:54:00 AM", "1:53:00 AM", "1:51:00 AM", "1:51:00 AM", "1:50:00 AM", "1:48:00 AM"),
Day=c("Wed", "Wed", "Mon", "Tue", "Mon", "Sun", "Sun", "Sun", "Sun"))
data$Day <- factor(data$Day,levels=c("Mon","Tue","Wed","Thu","Fri","Sat","Sun"))
data2 <- strptime(paste(data$Time, as.numeric(data$Day), data$Day,sep=" "), format="%H:%M:%S %p %d %a")
hist(data2, breaks="hours", start.on.monday=TRUE, format="%H:%M:%S %p %d")