# Based on demo from this website # https://www.r-bloggers.com/how-many-downloads-does-my-package-have/ # install.packages("cranlogs") library(cranlogs) library(ggplot2) library(dplyr) library(xgxr) library(ggrepel) xgx_theme_set() # How many overall downloads data <- cran_downloads(packages = c("xgxr","nlmixr","nlmixr2","RxODE","rxode2","ggPMX","RBesT","mrgsolve","PKNCA","NonCompart","ggplot2","rstan","deSolve","rms","brms"), from = "2010-01-01", to = Sys.Date()-1) %>% group_by(package) %>% mutate(cumulative = cumsum(count)) %>% filter(cumulative > 0) data_pmx = data %>% filter(!(package %in% c("ggplot2","rstan","deSolve","rms","brms"))) data_pmx_yearly = data_pmx %>% mutate(year = format(date, "%Y")) %>% select(-date, -cumulative) %>% group_by(package, year) %>% summarise(count = sum(count)) %>% ungroup() %>% mutate(year = as.numeric(year)) data_last = data %>% filter(date == max(date)) %>% mutate(date = date + 100) data_pmx_last = data_last %>% filter(!(package %in% c("ggplot2","rstan","deSolve","rms","brms"))) # Monthly downloads ---- g = ggplot(data_pmx_yearly, aes(x = year, y = count, color = package)) g = g + geom_line() g = g + geom_point() g = g + labs(x = "Date", y = "Yearly downloads", title = "Yearly downloads") g = g + theme(axis.text.x = element_text(angle = 45, hjust = 1)) g = g + facet_wrap(~package) print(g) # Cumulative Downloads ---- g = ggplot(data_pmx, aes(x = date, y = cumulative, color = package, label = package)) g = g + geom_line(size = 1, alpha = 0.5, show.legend = FALSE) g = g + labs(x = "Date", y = "Total downloads", title = "Cumulative downloads") g = g + geom_text_repel(data = data_pmx_last, direction = "y", hjust = .5, show.legend = FALSE) g = g + theme(legend.position = NULL) print(g) # Cumulative Downloads ---- g = ggplot(data, aes(x = date, y = cumulative, color = package, label = package)) g = g + geom_line(size = 1, alpha = 0.5, show.legend = FALSE) g = g + labs(x = "Date", y = "Total downloads", title = "Cumulative downloads, including commonly used packages") g = g + geom_text_repel(data = data_last, direction = "y", hjust = .5, show.legend = FALSE) g = g + theme(legend.position = NULL) g = g + xgx_scale_y_log10(limits = c(300,max(data$cumulative))) print(g)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.