Statistics for poppr installations.
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
if (!require('devtools')) install.packages('devtools'); require('devtools') | |
if (!require('data.table')) install.packages('data.table'); require('data.table') | |
install_github('installr', 'talgalili') # get the latest installr R package | |
# or run the code from here: | |
# https://github.com/talgalili/installr/blob/master/R/RStudio_CRAN_data.r | |
require(installr) | |
if(!require(ISOcodes)) install.packages("ISOcodes", repos = "http://cran.at.r-project.org"); require(ISOcodes) | |
folder <- "~/Documents/poppr_stats" | |
current_files <- dir(folder) | |
poppr_data <- list() | |
if(length(current_files) == 0 | file.info(current_files[1])$size == 0){ | |
start_date <- '2013-04-26' | |
} else { | |
start_date <- strsplit(current_files[length(current_files)], "[.]")[[1]][1] | |
start_date <- substr(start_date, 12, nchar(start_date)) | |
poppr_data[["old"]] <- read.table(current_files[length(current_files)], header = TRUE, | |
sep = ",", quote = "\"", dec = ".", fill = TRUE, | |
stringsAsFactors = FALSE, comment.char = "", | |
as.is=TRUE, check.names = FALSE) | |
} | |
print(start_date) | |
if(start_date != Sys.Date()){ | |
folder <- download_RStudio_CRAN_data(START = start_date, END = Sys.Date() - 1, log_folder = folder) | |
} | |
out_file <- paste("poppr_data_", Sys.Date(), ".csv", sep = "") | |
if (start_date != Sys.Date()){ | |
poppr_data[["new"]] <- read_RStudio_CRAN_data(folder) | |
my_RStudio_CRAN_data <- rbindlist(poppr_data) | |
} else { | |
my_RStudio_CRAN_data <- poppr_data[["old"]] | |
} | |
barplot_package_users_per_day("poppr", my_RStudio_CRAN_data) | |
poppr_data <- my_RStudio_CRAN_data[my_RStudio_CRAN_data$package %in% "poppr", ] | |
unlink("*gz") | |
write.table(poppr_data, file = out_file, sep = ",", row.names=FALSE, col.names=TRUE) | |
unique_poppr <- poppr_data[!duplicated(poppr_data$ip_id), ] | |
data(ISO_3166_1) | |
isoidx <- which(ISO_3166_1$Alpha_2 %in% unique_poppr$country) | |
iso <- ISO_3166_1[isoidx, ] | |
invisible(lapply(iso$Alpha_2, function(x) | |
unique_poppr$country[which(unique_poppr$country == x)] <<- iso[iso$Alpha_2 == x, "Name"])) | |
unique_poppr$total <- rep(cumsum(table(unique_poppr$date)), table(unique_poppr$date)) | |
require(ggplot2) | |
by_date <- ggplot(unique_poppr) + geom_histogram(aes(x = date, fill = country)) + theme_bw() + theme(axis.text.x=element_text(size = 10, angle=45, hjust=1, vjust=1)) + labs(title = paste("Poppr installations by date as of", Sys.Date(), sep = "\n")) + annotate("text", x = 1, y = 6, label = paste("Total:", nrow(unique_poppr)), hjust = 0, vjust = 1.1, size = 12) | |
res <- paste(folder,"results", sep = "_") | |
ggsave(plot = by_date, file = paste(res, "/inst_by_date_", Sys.Date(), ".pdf", sep = ""), scale = 2, width = 11, height = 8.5) | |
by_country <- ggplot(unique_poppr) + geom_histogram(aes(x = country, fill = country)) + theme_bw() + theme(axis.text.x=element_text(size = 10, angle=45, hjust=1, vjust=1)) + labs(title = paste("Poppr installations by country as of", Sys.Date(), sep = "\n")) + annotate("text", x = 1, y = 10, label = paste("Total:", nrow(unique_poppr)), hjust = 0, vjust = 1.1, size = 12) | |
ggsave(plot = by_country, file = paste(res, "/inst_by_country_", Sys.Date(), ".pdf", sep = ""), scale = 2, width = 11, height = 8.5) | |
by_total <- ggplot(unique_poppr) + geom_point(aes(x = date, y = total, color = version)) + theme_bw() + theme(axis.text.x=element_text(size = 10, angle=45, hjust=1, vjust=1)) + labs(title = paste("Total Poppr installations as of", Sys.Date(), sep = "\n")) + annotate("text", x = 1, y = nrow(unique_poppr), label = paste("Total:", nrow(unique_poppr)), hjust = 0, vjust = 1.1, size = 12, color = "red") | |
ggsave(plot = by_total, file = paste(res, "/inst_total_", Sys.Date(), ".pdf", sep = ""), scale = 2, width = 11, height = 8.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment