Created
February 1, 2023 18:50
-
-
Save kadyb/3970354b818f0a6cdf33987e05ef4068 to your computer and use it in GitHub Desktop.
Download statistics of spatial packages in R
This file contains hidden or 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("tidyr") | |
library("ggplot2") | |
library("cranlogs") | |
packages = c("sf", "stars", "terra", "raster", "exactextractr", | |
"rnaturalearth", "tidycensus", "s2") | |
df2021 = cran_downloads(packages, from = "2021-01-01", to = "2021-12-31") | |
df2022 = cran_downloads(packages, from = "2022-01-01", to = "2022-12-31") | |
## remove outliers | |
df2021[df2021$count == 99146, "count"] = 859 # terra (2021-04-23) | |
df2021[df2021$count == 39074, "count"] = 752 # terra (2021-04-24) | |
## aggregate by sum | |
agg2021 = aggregate(count ~ package, data = df2021, FUN = sum) | |
agg2022 = aggregate(count ~ package, data = df2022, FUN = sum) | |
df = data.frame("package" = agg2021$package, "sum2021" = agg2021$count, | |
"sum2022" = agg2022$count) | |
df$perc = (df$sum2022 - df$sum2021) / df$sum2021 * 100 | |
df$perc = round(df$perc) | |
### plot ### | |
df = pivot_longer(df, c("sum2021", "sum2022"), names_to = "year", values_to = "sum") | |
df$year = factor(df$year, labels = c(2021, 2022)) | |
df$package = factor(df$package) | |
df$sum = round(df$sum / 1000) | |
df$perc = paste0("+", df$perc, "%") | |
df$perc[seq(1, 16, by = 2)] = NA | |
ggplot(df, aes(x = year, y = log10(sum), group = package, color = package)) + | |
geom_line() + | |
geom_point() + | |
scale_color_brewer(palette = "Dark2", name = "Package") + | |
geom_text(aes(label = sum), nudge_x = c(-0.1, 0.1), show.legend = FALSE) + | |
geom_text(aes(label = perc), nudge_x = 0.25, fontface = "bold", show.legend = FALSE) + | |
labs(title = "Download statistics of spatial packages in R (in thousands)", | |
caption = "Only downloads from RStudio CRAN mirror are included") + | |
xlab("Year") + | |
theme(axis.title.y = element_blank(), | |
axis.text.y = element_blank(), | |
axis.ticks.y = element_blank(), | |
panel.background = element_blank(), | |
legend.key = element_blank(), | |
plot.title = element_text(hjust = 0.5, face = "bold")) | |
ggsave("plot.pdf", width = 7, height = 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment