Last active
August 29, 2015 13:57
-
-
Save johnjosephhorton/9552382 to your computer and use it in GitHub Desktop.
Code for making "Active Window" trends plot on http://john-joseph-horton.com/
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
library(JJHmisc) | |
library(oDeskTools) #internal package for working with oDesk data | |
library(ggplot2) | |
library(reshape2) | |
library(scales) | |
connectDB(get_credentials()) | |
df.wide <- dbGetQuery(con, "select * from active_window_trends") | |
df <- melt(df.wide, id.vars = c("year")) | |
df.compare <- merge(subset(df, year == 2010), | |
subset(df, year == 2013), by = "variable") | |
df.compare$pct <- with(df.compare, round(100 * (value.y - value.x)/value.x)) | |
df.compare$pct.label <- with(df.compare, sprintf('%.1f', pct)) | |
df.final <- merge(df, df.compare[, c("variable", "pct.label", "pct")]) | |
df.final$better.label <- with(df.final, paste0(variable,": ", pct.label, "%")) | |
df.final$direction <- with(df.final, sign(pct)) | |
g <- ggplot(data = df.final, aes(x = year, y = value)) + | |
geom_line(aes(group = variable)) + | |
geom_text(data = subset(df.final, year == 2013), | |
aes(x = year, | |
y = value, | |
hjust = 0, | |
colour = factor(direction), | |
label = better.label)) + | |
geom_text(data = subset(df.final, year == 2010), | |
aes(x = year, | |
y = value, | |
hjust = 1, | |
colour = factor(direction), | |
label = variable)) + | |
theme_bw() + | |
scale_y_log10(labels = percent) + | |
scale_colour_manual(values=c("red", "darkgreen")) + | |
xlab("Year") + | |
ylab("Percentage of Observations for Month of August (Log Scale)") + | |
theme(legend.position = "none") + | |
labs(title = "Changes in Freelancer 'Active Window'") | |
writeImage(g, "what_freelancers_use", width = 9, height = 12, path = "./") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment