Skip to content

Instantly share code, notes, and snippets.

@davidcoallier
Created April 22, 2013 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidcoallier/5438020 to your computer and use it in GitHub Desktop.
Save davidcoallier/5438020 to your computer and use it in GitHub Desktop.
user created.at pages.visited
julie 2011-11-16 03:31:56 GMT 3
julie 2011-11-16 04:22:33 GMT 5
jack 2011-11-16 07:19:13 GMT 8
jack 2011-11-16 12:39:02 GMT 9
julie 2011-11-17 12:39:02 GMT 3
ggplot(byHour, aes(x=hour, y=as.numeric(countPerHour))) +
geom_bar(aes(fill=user), stat="identity") +
labs(title="Pages visited per hour of day") +
ylab("Visits Per Hour") + xlab("Hour of the day") +
theme_bw() + facet_grid(user~.)
ggplot(byWeekday, aes(x=weekday, y=as.numeric(countPerDay))) +
geom_bar(aes(fill=user), position="dodge") +
labs(title="Dodge per hour per user") +
ylab("Visits Per Hour") + xlab("Hour of the day") +
theme_bw() + coord_flip()
byWeekdayHour <- ddply(data, .(user, hour, weekday), summarise, countPerHour=sum(pages.visited))
byWeekdayHour$weekday <- factor(
byWeekdayHour$weekday,
levels=c('Wednesday', 'Thursday')
)
ggplot(byWeekdayHour, aes(x=hour, y=as.numeric(countPerHour))) +
geom_bar(aes(fill=user), stat="identity") +
labs(title="Pages visited per hour of day") +
ylab("Visits Per Hour") + xlab("Hour of the day") +
theme_bw() + facet_grid(user~weekday)
require(Hmisc)
require(plyr)
require(ggplot2)
data <- csv.get('path/to/csv-file.csv', header=TRUE)
data$created.at <- as.POSIXct(
format(data$created.at, tz="America/Los_Angeles" usetz=TRUE)
)
data$hour <- format(data$created.at, '%H')
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
user created.at pages.visited hour
1 julie 2011-11-16 03:31:56 3 03
2 julie 2011-11-16 04:22:33 5 04
3 jack 2011-11-16 07:19:13 8 07
4 jack 2011-11-16 12:39:02 9 12
5 julie 2011-11-17 12:39:02 3 12
byHour <- ddply(data, .(user, hour), summarise, countPerHour=sum(pages.visited))
data$weekday <- weekdays(data$created.at)
byWeekday <- ddply(data, .(user, weekday), summarise, countPerDay=sum(pages.visited))
ggplot(byHour, aes(x=hour, y=as.numeric(countPerHour))) +
geom_bar(stat="identity") +
labs(title="Count per hour for all users") +
ylab("Visits Per Hour") + xlab("Hour of the day") +
theme_bw()
ggplot(byHour, aes(x=hour, y=as.numeric(countPerHour))) +
geom_bar(aes(fill=user), position="dodge") +
labs(title="Dodge per hour per user") +
ylab("Visits Per Hour") + xlab("Hour of the day") +
theme_bw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment