Created
April 22, 2013 20:01
-
-
Save davidcoallier/5438020 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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~.) |
This file contains hidden or 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
| 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() |
This file contains hidden or 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
| 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) |
This file contains hidden or 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
| require(Hmisc) | |
| require(plyr) | |
| require(ggplot2) | |
| data <- csv.get('path/to/csv-file.csv', header=TRUE) |
This file contains hidden or 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
| data$created.at <- as.POSIXct( | |
| format(data$created.at, tz="America/Los_Angeles" usetz=TRUE) | |
| ) |
This file contains hidden or 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
| 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.
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| byHour <- ddply(data, .(user, hour), summarise, countPerHour=sum(pages.visited)) |
This file contains hidden or 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
| data$weekday <- weekdays(data$created.at) | |
| byWeekday <- ddply(data, .(user, weekday), summarise, countPerDay=sum(pages.visited)) |
This file contains hidden or 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
| 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() |
This file contains hidden or 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
| 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