7 d = read.delim("mail_metadata.tsv", header=FALSE,
8 col.names=c("flags", "timestamp", "precedence", "google"))
10 d$timestamp <- as.POSIXct(d$timestamp, tz="UTC",
11 origin=as.POSIXct("1970-01-01 00:00:00"))
13 # limit the dataset to emails sent post timestamp
14 d <- d[d$timestamp > as.POSIXct("2004-04-01 00:00:00"),]
16 d$week <- cut(d$timestamp, breaks="weeks")
18 # list and then drop list mail
20 d <- d[is.na(d$precedence),]
23 d$replied <- grepl('R', d$flags)
25 google.by.week <- function (d) {
28 weeks <- d[,list(total=length(google), google=table(google)["TRUE"]), by=week]
31 weeks <- weeks[weeks$total > 1,]
32 weeks$google.prop <- weeks$google / weeks$total
34 weeks$week <- as.Date(as.character(weeks$week))
39 # find proportions per year
40 replied <- google.by.week(d[d$replied,])
41 replied <- replied[complete.cases(replied),]
43 replied.tbl <- as.data.frame(
44 tapply(replied$google, substr(as.character(replied$week), 1, 4), sum) /
45 tapply(replied$total, substr(as.character(replied$week), 1, 4), sum))
47 colnames(replied.tbl) <- "prop.google"
48 replied.tbl$year <- row.names(replied.tbl)
49 row.names(replied.tbl) <- NULL
51 ggplot(data=replied.tbl) + aes(x=year, y=prop.google) +
52 geom_bar(stat="identity")
56 # Graph #1: Emails from Google Over Time
57 #######################################################
59 raw.data <- google.by.week(d)
60 raw.data$google.prop <- NULL
62 raw.data <- melt(raw.data, id.var="week")
65 pdf(file="emails_gmail_over_time.pdf", width=10, height=6)
67 ggplot(data=raw.data) + aes(x=week, y=value, color=variable, group=variable) +
69 stat_smooth(method="loess", show_guide=FALSE) +
70 scale_color_discrete("", breaks=c("total", "google"),
71 labels=c("All Emails", "From Google")) +
72 scale_x_date("Date") +
73 scale_y_continuous("Number of Emails")
77 # Graph #2: Proportions of Email from Google
78 #######################################################
80 prop.data <- rbind(cbind(google.by.week(d), subset="All Email"),
81 cbind(google.by.week(d[d$replied]), subset="Email with Replies"))
84 pdf(file="emails_gmail_prop_over_time.pdf", width=10, height=8)
86 ggplot(data=prop.data) + aes(x=week, y=google.prop, size=total, group=subset) +
87 geom_point() + facet_grid(subset~.) +
88 scale_y_continuous("Proportion from Google", limits=c(0,1)) +
89 scale_x_date("Date") +
90 scale_size("Emails") +
91 stat_smooth(method="loess", show_guide=FALSE)