, juba ggplot2, , , .
, , .
hh:mm
decTime <- function(x) {
t <- as.numeric(strsplit(x, ":")[[1]])
t <- t[1] + t[2]/60
return(t)
}
str <- 'n day tstart tend duration category
1 2012-10-01 13:40 14:16 36 Recreation
2 2012-10-02 10:15 10:57 42 Work
3 2012-10-02 13:23 13:47 24 Chores
4 2012-10-02 13:47 14:48 61 Work
5 2012-10-03 09:09 11:40 151 Work
6 2012-10-03 13:33 14:04 31 Recreation
7 2012-10-03 17:00 19:40 160 Recreation'
df <- read.table(textConnection(str), header=T)
( )
df$day <- gsub('2012-10-', "", df$day)
df$day <- as.numeric(df$day)
df$starttime <- sapply(as.character(df$tstart), decTime, USE.NAMES=F)
df$endtime <- sapply(as.character(df$tend), decTime, USE.NAMES=F)
df$color <- ifelse(df$category=='Recreation', 'RED', ifelse(df$category =='Chores', 'BLUE', 'GREEN'))
plot(x=unique(df$day), y=c(0,0,0), axes=F, ylim=c(0,24), xlim=c(0.5,3.5), xlab='date', ylab='time', type='n')
axis(side=1, at=c(1,2,3), labels=c('01', '02', '03'))
axis(side=2, at=seq(from=0,to=24,by=1), labels=seq(from=0,to=24,by=1))
rect(df$day-0.25, df$starttime, df$day+0.25, df$endtime, col=df$color)
.
