Skip to content

Instantly share code, notes, and snippets.

@jdeboer
Created August 18, 2018 08:52
Show Gist options
  • Save jdeboer/bd8f7728339dc11d3479d56fa2645702 to your computer and use it in GitHub Desktop.
Save jdeboer/bd8f7728339dc11d3479d56fa2645702 to your computer and use it in GitHub Desktop.
Generate a trend plot showing the cumulative downloads of Google Analytics R packages via RStudio's CRAN mirror. The data is accessed using the cranlogs package.
library(tidyverse)
packages <- c("ganalytics", "googleAnalyticsR", "RGoogleAnalyticsPremium", "RGA", "GAR")
df_raw <- cranlogs::cran_downloads(packages, from = "2013-04-09", to = Sys.Date() - 1L)
df <- tbl_df(df_raw) %>%
group_by(package) %>% mutate(count = cumsum(count)) %>% ungroup() %>%
filter(count > 0L) %>%
mutate(package = factor(package) %>% fct_reorder(count, max, .desc = TRUE))
ggplot(df) +
aes(date, count, fill = package) +
geom_area(alpha = 0.5) +
scale_y_continuous(labels = scales::comma, name = "Cumulative downloads") +
scale_fill_discrete(name = "Package") +
ggtitle("Cumulative downloads of Google Analytics packages via RStudio's CRAN mirror.\n(Data accessed via the cranlogs package)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment