Last active
December 7, 2020 13:44
-
-
Save yannikbuhl/c84c3cbf94cee3091471a2b296a90995 to your computer and use it in GitHub Desktop.
Plotting cumulative or daily downloads of your R package on CRAN
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
library(cranlogs) | |
library(ggplot2) | |
cran <- function(package, cumulative = FALSE, from = "2019-01-01") { | |
# Get downloads | |
mls <- cran_downloads(packages = package, from = from, to = Sys.Date() - 1) | |
if (cumulative == FALSE) { | |
# Plot non-cumulative package downloads | |
gr0 <- ggplot(mls, aes(date, count)) + | |
geom_line(colour = "red", size = 1) | |
gr0 + xlab("Time") + ylab("Nr. of downloads") + | |
labs(title = paste0("Daily downloads ", Sys.Date() - 1)) | |
} else { | |
# Plot cumulative downloads | |
cumulative <- cumsum(mls[,2]) | |
mls2 <- cbind(mls, cumulative) | |
gr1 <- ggplot(mls2, aes(date, cumulative)) + | |
geom_line(colour = "blue", size = 1) | |
gr1 + xlab("Time") + ylab("Nr. of downloads") + | |
labs(title = paste0("Downloads until ", Sys.Date() - 1)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment