Posts

Today I made a quick graph of the player payrolls for the Cleveland baseball team to compare their projected payroll after today’s trade with the Mets (Lindor, Carrasco, etc.) to past seasons. Sources: (past) http://www.stevetheump.com/Payrolls.htm (2021 projection) https://twitter.com/ZackMeisel/status/1347246681520295936 https://teamcolorcodes.com/cleveland-indians-color-codes/ years <- 2014:2021 payrolls <- c(82.5, 86.1, 86.3, 124.3, 134.4, 88.7, 37.6, 35) df <- data.frame(years, payrolls) df %>% ggplot(aes(x = years, y = payrolls, label = payrolls)) + geom_bar(stat = "identity", fill = "#E31937", color = "#0C2340") + geom_label() + labs(title = "Opening Day Payrolls of the Cleveland Baseball Team", subtitle = "2016: World Series appearance\n2020: pandemic-shortened season\n2021: projected", caption = "Sources: http://www.

CONTINUE READING

Source: Create Bart Simpson Blackboard Memes with R

knitr::opts_chunk$set(echo = TRUE)

library("meme")
## Warning: package 'meme' was built under R version 4.0.3
if (.Platform$OS.type == "windows") {
  windowsFonts(Comic = windowsFont("Comic Sans MS"))
}
bart <- "bart_simpson_chalkboard-5157.gif" # source: http://free-extras.com/images/bart_simpson_chalkboard-5157.htm
text <- paste(rep("I will not procrastinate \n in grant writing \n by making memes in R instead", 2), collapse = "\n")
meme(bart, text, size = 2, font = "Comic")

CONTINUE READING

Data Source: USA Facts — downloaded July 6, 2020 library("tidyverse") library("zoo") start_date <- "5/28/20" end_date <- "7/5/20" county_list <- c("Santa Clara", "Stanislaus", "Calaveras", "San Benito", "Merced", "Tuolumne", "Fresno", "Madera", "Mariposa") lag <- 7 #number of days for rolling average #loads files cases_raw <- read_csv("covid_confirmed_usafacts.csv") populations <- read_csv("covid_county_population_usafacts.csv") Data Wrangling raw_data_merged <- cases_raw %>% full_join(populations, by = c("County Name", "State")) # find column positions by date column_names <- colnames(raw_data_merged) start_loc <- match(start_date, column_names) end_loc <- match(end_date, column_names) cases_filtered <- cases_raw %>% filter(State == "CA") %>% select("County Name", all_of(start_loc:end_loc)) populations_filtered <- populations %>% filter(State == "CA") %>% select("County Name", "population") df_merged <- cases_filtered %>% full_join(populations_filtered, by = "County Name") df_clean <- df_merged %>% # avoids unallocated cases and the cruise ship!

CONTINUE READING

Introduction Today, for practice with ggplot2, I wish to replicate @JoshuaFeldman’s wonderful #TidyTuesday submission about the dataset of Roman emperors. library("tidyverse") TidyTuesday’s Roman Emperor dataset — posted on August 13, 2019 # TidyTuesday's given line of code to load the data emperors <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-08-13/emperors.csv") Exploring the Data dim(emperors) ## [1] 68 16 colnames(emperors) ## [1] "index" "name" "name_full" "birth" "death" ## [6] "birth_cty" "birth_prv" "rise" "reign_start" "reign_end" ## [11] "cause" "killer" "dynasty" "era" "notes" ## [16] "verif_who" emperors %>% filter(birth_prv !

CONTINUE READING

Introduction library("tidyverse") Today, I am going to create an overly simplified view of the past 10 Supreme Court decisions for the sake of coding practice with the ggplot package. data source: SCOTUS Blog useful tool: Convert Town’s “Column to Comma Separated Values” function Data Just in case anyone actually uses my blog post, I will type out the data manually instead of load a separate CSV file so that anyone can copy-and-paste the code for replicability.

CONTINUE READING

Introduction Today’s coding practice is based on the following article and data source (there is literally a “Get the Data” link): Here’s a List of Colleges’ Plans for Reopening in the Fall library("geofacet") library("rvest") library("tidyverse") # load data df_raw <- read_csv("data-w8lLG.csv") colnames(df_raw) ## [1] "Institution" "Control" "State" "Category" Data Wrangling # filter out Excel artifacts (trivial, empty rows) df <- df_raw %>% filter(Institution != "#REF!") #States as factors states_alphabetically <- sort(unique(df$State)) df$State_factor <- factor(df$State, levels = states_alphabetically) #extracting text from urls (rvest!

CONTINUE READING

If you are planning to do the R assignments on your own computer (recommended), then here is a quick outline for obtaining the software. There are two separate software programs. Most people find it easier to use RStudio. than just R, but you need to install R first before installing RStudio (analogously speaking: you need an cell phone before you can use an cell phone case). If you have R and RStudio from a previous course, you still need to update to the current versions!

CONTINUE READING

Today I am going to try to make a geofacet graph using the GAI (Global Acceptability Index) data. My goal is to show trends in LGBT acceptance in Europe between the years 2003 and 2017. Sources and tools Social Acceptance of LGBT People in 174 Countries publication from the UCLA School of Law Williams Institute geofacet R package List of European nations Convert Town to convert spreadsheet columns to comma-separated lists library("geofacet") library("tidyverse") Data raw_data <- read_csv("gai.

CONTINUE READING

Inspired by this morning’s meeting of the Bisexual Research Group, I am going to draft a quick map of LGBT acceptance in Africa. Sources and tools Social Acceptance of LGBT People in 174 Countries publication from the UCLA School of Law Williams Institute List of African nations SimplyPDF to extract table of data from a PDF document Convert Town to convert spreadsheet columns to comma-separated lists library("tidyverse") Data rank <- 1:174 countries_text <- "Iceland,Netherlands,Norway,Canada,Spain,Belgium,Ireland,Sweden,Denmark,Nepal,Great Britain,Luxembourg,Malta,Uruguay,New Zealand,Germany,Finland,Switzerland,Puerto Rico,Australia,United States,France,Argentina,Austria,Brazil,Cape Verde,Chile,Philippines,Hong Kong,Italy,Portugal,Mexico,South Africa,Costa Rica,Cuba,Czech Republic,Colombia,Slovenia,Venezuela,Taiwan,Ecuador,Nicaragua,Bahrain,Bolivia,Israel,Suriname,Laos,Syria,Panama,El Salvador,Mauritius,Northern Cyprus,Peru,Croatia,Dominican Republic,Namibia,Honduras,Paraguay,Cyprus,Thailand,Slovakia,Greece,Mozambique,Andorra,Hungary,Japan,South Korea,Estonia,Myanmar,Poland,Bangladesh,Barbados,Cambodia,Guatemala,Singapore,Sao Tome and Principe,Trinidad and Tobago,Guyana,Bulgaria,Vietnam,India,Botswana,Grenada,Latvia,Turkey,Bahamas,Belize,Saint Kitts and Nevis,Malaysia,Serbia,Algeria,Lithuania,Jamaica,Dominica,Romania,Bhutan,Lebanon,Saint Lucia,Swaziland,Lesotho,China,Antigua and Barbuda,Angola,Yemen,Benin,Haiti,Uzbekistan,Libya,Montenegro,Tunisia,Saint Vincent and the Grenadines,Kuwait,Uganda,Jordan,Albania,Belarus,Gambia,Morocco,Kenya,Russia,Democratic Republic of the Congo,Ukraine,Qatar,Palestine,Madagascar,Tanzania,Cote d'Ivoire,Republic of the Congo,Iraq,Gabon,Kazakhstan,Sudan,Bosnia Herzegovina,Sierra Leone,Macedonia,Comoros,Saudi Arabia,Burkina Faso,Togo,Kyrgyzstan,Ghana,Mongolia,Rwanda,Kosovo,Cameroon,Nigeria,Zambia,Central African Republic,Zimbabwe,Indonesia,Djibouti,Chad,Niger,Mali,Guinea,Afghanistan,Liberia,Moldova,Georgia,Burundi,South Sudan,Mauritania,Sri Lanka,Iran,Pakistan,Malawi,Nagorno- Karabakh,Armenia,Egypt,Ethiopia,Somaliland,Senegal,Azerbaijan,Tajikistan" country <- str_split(countries_text,",")[[1]] GAI_text <- "8.

CONTINUE READING

library("dplyr") library("ggplot2") Data Today I am going to try to make a choropleth (map + data) of the percentage of registered voters that sent in ballots for the 2018 elections in the USA. I gathered the data from and by the following sites: Few States Are Prepared To Switch To Voting By Mail. That Could Make For A Messy Election — FiveThirtyEight artcle from April 27, 2020 How to Create a Comma Separated List from an Excel Column — from University of Pennsylvania states <- tolower( sort(c(state.

CONTINUE READING