Created
April 8, 2021 22:38
-
-
Save SPLOpenData/ac8e20395f0905fcd05237ff518f3c3c to your computer and use it in GitHub Desktop.
This R script creates a visualization showing CRAN packages by year added. Current (partial year excluded)
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
#This R script create a visualization showing CRAN packages by year added. | |
library(rvest) | |
library(ggplot2) | |
library(cowplot) | |
URL<- "https://cran.r-project.org/web/packages/available_packages_by_date.html" | |
#scrape table data from CRAN website | |
getthis<- xml2::read_html(URL) | |
cran_df<-rvest::html_table(getthis) %>% data.frame(.) | |
#Summarize data by year | |
new_by_year<- as.Date(cran_df$Date) %>% | |
format(., "%Y") %>% table(.) %>% data.frame(.) | |
names(new_by_year)[1]<-"year" | |
#get today's date | |
today_is<-Sys.Date() | |
#Exclude data for the current (partial) year | |
new_by_year <- new_by_year[!new_by_year$year == (today_is %>% format(., "%Y")),] | |
#plot | |
p<-ggplot(new_by_year, mapping=aes(year, Freq))+ | |
geom_col(fill = "skyblue2", alpha = 0.7) + | |
scale_y_continuous(expand = expansion(mult = c(0, 0.05))) + | |
theme_minimal_hgrid(11)+ | |
ggtitle("Available CRAN packages By Publication Date")+ | |
labs(subtitle = paste0("Data captured: ", today_is," Excludes current year."))+ | |
ylab("# of packages") | |
p<-p+ theme(plot.title = element_text(size=32), | |
plot.subtitle = element_text(size=16), | |
axis.text = element_text(size = 15), | |
axis.title = element_text(size = 15)) | |
p | |
png(file="cran.png", | |
width=1200, height=700) | |
p | |
dev.off() |
Author
SPLOpenData
commented
Apr 8, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment