Created
March 21, 2010 23:08
-
-
Save pecard/339640 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! Gráfico de Barras GGPLOT | |
#! Paulo Eduardo Cardoso | |
library(chron) | |
library(ggplot2) | |
horas <- read.table("clipboard",header=T) | |
horas <- strptime(as.character(horas[,1]),"%H:%M:%S") | |
horaH <- data.frame("Hora"=hours(horas)) | |
horasdia <- data.frame("Hora"=c(0:23)) | |
postsH <- as.data.frame(table(horaH)) | |
postsDia <- merge(horasdia,postsH,by.x="Hora",by.y="horaH",all.x=T) | |
postsDia$Freq[is.na(postsDia$Freq)==T] <- 0 | |
diaTrab<-data.frame("Período"=c("Pós laboral","Laboral","Pós laboral"),"inicio"=c(0,8.5,18.5), "fim"=c(8.5,18.5,24.5)) | |
graf <- qplot(postsDia$Hora,postsDia$Freq,geom="bar",stat="identity", fill = I("grey50"),xlab="Hora",ylab="N.º de Mensagens") | |
graf + geom_rect(aes(NULL, NULL, xmin = inicio, xmax = fim, fill = Período), ymin = 0, ymax = max(postsDia$Freq),data = diaTrab) + | |
scale_fill_manual(values =alpha(c("blue","red"), 0.2)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment