Created
January 9, 2014 22:13
-
-
Save blmoore/8343067 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
require(ggplot2) | |
lm_eqn <- function(m) { | |
# fromm: http://stackoverflow.com/a/13451587/1274516 | |
l <- list(a = format(coef(m)[1], digits = 2), | |
b = format(abs(coef(m)[2]), digits = 2), | |
r2 = format(summary(m)$r.squared, digits = 3)); | |
if (coef(m)[2] >= 0) { | |
eq <- substitute(italic(y) == a + b %.% italic(x)*","~~italic(r)^2~"="~r2,l) | |
} else { | |
eq <- substitute(italic(y) == a - b %.% italic(x)*","~~italic(r)^2~"="~r2,l) | |
} | |
as.character(as.expression(eq)); | |
} | |
views <- read.csv("http://reportcard.wmflabs.org/data/datafiles/rc/rc_page_requests.csv") | |
views$Month <- as.Date(views$Month) | |
ggplot(views, aes(x=Month, y=English/10e6)) + | |
geom_line() + geom_smooth(method="loess", col="red") + | |
labs(y="Pageviews (Million)", x="", | |
title="en.wiki monthly pageviews 2008-14") + | |
theme_bw() | |
mobile <- read.csv("http://reportcard.wmflabs.org/data/datafiles/rc/rc_page_requests_mobile.csv") | |
mobile$Month <- as.Date(mobile$Month) | |
ggplot(mobile, aes(x=Month, y=English.Mobile/10e6)) + | |
geom_line() + labs(y="Pageviews (Million)", x="", | |
title="en.wiki mobile monthly pageviews 2008-14") + | |
geom_smooth(method="lm", col="darkgreen") + | |
theme_bw() + geom_point() + | |
annotate("text", x = as.Date("2013-01-01"), y = 50, col="darkgreen", size=6, | |
label = lm_eqn(lm(English.Mobile/10e6 ~ Month, mobile)), parse = TRUE) | |
uv <- read.csv("http://reportcard.wmflabs.org/data/datafiles/rc/rc_comscore_region_uv.csv") | |
uv$date <- as.Date(uv$date) | |
# filter non-matched dates | |
uv <- uv[uv$date %in% views$Month,] | |
views <- views[-nrow(views),] | |
vvu <- data.frame(month=views$Month, views=views$English, uv=uv$World) | |
ggplot(vvu, aes(x=month, y=views/uv)) + | |
geom_line() + geom_smooth(method="loess") + | |
labs(y="Mean pageviews per unique visitor", x="") + | |
theme_classic() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment