简体   繁体   中英

How to plot time in a range in R?

I have a dataframe df as

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

I want to plot a graph where I can plot the time in a range like 12am-2am, 2am-4am, and so on vs day

Please help.

Think this is essentially what you are after

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM