Skip to content

Instantly share code, notes, and snippets.

@yannikbuhl
Last active December 7, 2020 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yannikbuhl/c84c3cbf94cee3091471a2b296a90995 to your computer and use it in GitHub Desktop.
Save yannikbuhl/c84c3cbf94cee3091471a2b296a90995 to your computer and use it in GitHub Desktop.
Plotting cumulative or daily downloads of your R package on CRAN
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