Skip to content

Instantly share code, notes, and snippets.

@Ironholds
Created July 9, 2013 22:38
Show Gist options
  • Save Ironholds/5961944 to your computer and use it in GitHub Desktop.
Save Ironholds/5961944 to your computer and use it in GitHub Desktop.
happy? ;p
#Data on registrations
registrations.fun <- function(x, graphname, filename){
#Aggregate
aggregate.data <- as.data.frame(
table(x$registration_date
)
)
#Plot registrations
assign("registration.plot",ggplot(data = aggregate.data,
aes(x=Var1, y = Freq, width=.5)) +
geom_bar(width=.5, fill = "red", stat = "identity", position = "dodge") +
labs(x = "Year", y = "Number of registrations") +
theme(axis.text.x=element_text(angle = -90, hjust = 1)) +
ggtitle(paste("English-language Wikipedia account registrations by ",graphname, sep = " ")), envir = .GlobalEnv)
#Print
ggsave(filename = file.path(getwd(),"Output", paste("account_registrations_by_",filename,".png", sep = "")),
plot = registration.plot,
width = 8,
height = 8,
units = "in")
#Write
aggregate_file_path <- file.path(getwd(),"Output",paste("account_registrations_by_",filename,".png", sep = ""))
write.table(aggregate.data, file = aggregate_file_path, col.names = TRUE,
row.names = FALSE, sep = "\t", quote = FALSE)
}
registrations.fun(x = query.df, filename = "year", graphname = "year")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment