email habits over time
[This article was first published on idle thoughts » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
I was curious if my sleeping/waking habits had really changed over the years – I definitely don’t feel I work as late now as when I was 22, but it’s hard to tell. To test this, I looked over all of the timestamps of mail I’ve sent in the past few years and tried to make a pretty graph.
I’m not sure how meaningful it is, but thanks to ggplot, it is pretty, at least.
The plotting code is straightforward — try it out!
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
library("ggplot2") | |
library("reshape") | |
getData = function() { | |
SOURCE=Sys.glob('/home/power/.thunderbird/*/*/*/*/Sent Mail') | |
return(readLines(SOURCE)) | |
} | |
getMatches = function(data) { | |
matched_lines = grep('^Date:.*, .*-0\\d+', data, value=T) | |
return(gsub('Date:.*, (.*-0\\d+).*', '\\1', matched_lines)) | |
} | |
lines = getData() | |
matches = getMatches(lines) | |
dates = lapply(matches, function(f) {strptime(f, format="%d %b %Y %H:%M:%S %z")}) | |
df = ldply(dates, unlist) | |
df$year = df$year + 1900 | |
df_counts = count(df, vars=c("year", "hour")) | |
for (year in df_counts$year) { | |
m = df_counts$year == year | |
df_counts$freq[m] = df_counts$freq[m] / sum(df_counts$freq[m]) | |
} | |
p = ggplot(df_counts, aes(x=year, y=hour)) + | |
scale_x_continuous(limits=c(2004, 2012)) + | |
scale_y_datetime() + | |
geom_tile(aes(fill=freq)) + | |
scale_fill_gradient() | |
show(p) |
To leave a comment for the author, please follow the link and comment on their blog: idle thoughts » R.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.