Skip to content

Instantly share code, notes, and snippets.

@SPLOpenData
SPLOpenData / wordcloud_example_CRAN_package_titles.r
Created April 9, 2021 20:29
#This R script creates wordcloud of CRAN package titles since 2020.
#This R script creates wordcloud of CRAN package titles since 2020.
library(rvest)
library(ggplot2)
library(dplyr)
library(tokenizers)
library(SnowballC)
library(stopwords)
library(ggwordcloud)
URL<- "https://cran.r-project.org/web/packages/available_packages_by_date.html"
@SPLOpenData
SPLOpenData / CRAN_package_count_by_year_visualization.R
Created April 8, 2021 22:38
This R script creates a visualization showing CRAN packages by year added. Current (partial year excluded)
#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(.)
@SPLOpenData
SPLOpenData / Audio_visualization_with_R_tuneR.R
Last active July 23, 2021 15:44
"The Pulse of COVID" This R script creates an audio 'visualization' of COVID data from the CDC.
#"The Pulse of COVID"
#This R script creates an audio 'visualization' of covid data from the CDC.
#Notes on what you'll hear: (1) New cases aggregated to week are scaled as the volume and new deaths as the pitch.
#(2) The addition of new data over time will affect the scaled output sound of code re-reun in the future.
library(RSocrata) #For downloading CDC data.
library(tuneR) #Making a .wav file
library(dplyr)
library(lubridate) #Date math --aggregating daily data into weekly data.
#Download data from the CDC.
@SPLOpenData
SPLOpenData / ggpattern_magick_example.R
Last active March 22, 2021 23:39
#This R script demonstrates use of the library ggpattern to add image textures to visualizations + magick to edit image files.
#This R script demonstrates use of the library ggpattern to add image textures to visualizations + magick to edit image files
library(ggpattern) #remotes::install_github("coolbutuseless/ggpattern")
library(ggplot2)
library(magick)
library(tibble)
library(dplyr)
#create data to visualize
cakes<-tibble( cake_name=c("Chocolate Cake","Cream Cake ","Pound Cake",
"White or Yellow Cake","Devil’s Food Cake",
"Sponge Cake","Angel Food Cake","Water"),
@SPLOpenData
SPLOpenData / magick_ggplot2_example.R
Last active March 19, 2021 21:14
This example R script creates a visualization using ggplot2 with both ggtextures & magick images.
#Eample visualization to demonstrate use of ggplot + ggtextures + magick images``
library(magick)
library(ggplot2)
library(ggtextures) #Not on CRAN. Use: devtools::install_github("clauswilke/ggtextures")
library(dplyr)
#Source data 'https://www.icco.org/wp-content/uploads/Grindings_QBCS-XLVII-No.-1.pdf'
df<-tibble(country= c("Germany", "Cote d'ivoire", "Netherlands", "USA", "Indonesia"),
grindings= c(430, 610, 600, 385, 485),
flag_img= c("de","ci","nl","us","id"),
img = list(
@SPLOpenData
SPLOpenData / King_County_Parcel_getting_started.R
Last active April 9, 2021 22:18
This R script downloads King County WA parcel open data in R as an sf object, and creates point-based centroids for each_parcel.
#This R script downloads King County WA parcel open data in R as an sf object, and creates point-based centroids for each_parcel.
#This script is intented to help you get up and running.
#Tempfile used for downloading.
temp <- tempfile()
temp2 <- tempfile()
#Download the open data ArcGIS zip folder containing the parcel data as a .shp file.
# As an alternative, you can download KML or csv version from here: https://gis-kingcounty.opendata.arcgis.com/datasets/parcels-for-king-county-with-address-with-property-information-parcel-address-area
download.file("https://opendata.arcgis.com/datasets/c7a17b7ad3ec44b7ae64796dca691d72_1722.zip",temp)
#Unzip the contents of 'temp' object and save unzipped content in 'temp2'