Skip to content

Instantly share code, notes, and snippets.

View JosiahParry's full-sized avatar
🕵️‍♂️
sleuthing data

Josiah Parry JosiahParry

🕵️‍♂️
sleuthing data
View GitHub Profile
sq <- ggplot((na.omit(threats)), aes(factor(soil_quality)))+ geom_bar() + facet_grid(~Gender) + aes(fill = Gender)
wq <- ggplot((na.omit(threats)), aes(factor(waterquality))) + geom_bar()+ facet_grid(~Gender) + aes(fill = Gender)
wl <- ggplot((na.omit(threats)), aes(factor(wildlife))) + geom_bar()+ facet_grid(~Gender) + aes(fill = Gender)
rec <- ggplot((na.omit(threats)), aes(factor(recreation))) + geom_bar() + facet_grid(~Gender) + aes(fill = Gender)
scen <- ggplot((na.omit(threats)), aes(factor(scenic))) + geom_bar() + facet_grid(~Gender) + aes(fill = Gender)
tour <- ggplot((na.omit(threats)), aes(factor(tourism))) + geom_bar() + facet_grid(~Gender) + aes(fill = Gender)
biz <- ggplot((na.omit(threats)), aes(factor(business))) + geom_bar() + facet_grid(~Gender) + aes(fill = Gender)
rur <- ggplot((na.omit(threats)), aes(factor(rural))) + geom_bar() + facet_grid(~Gender) + aes(fill = Gender)
@JosiahParry
JosiahParry / multi_album_artists.txt
Created January 29, 2018 14:57
Multiple Album Tracklists and Lyrics
# Create a tibble with the artist's name & another with the album title
kdot_albums <- tibble(
artist = "Kendrick Lamar",
album = c("Section 80", "DAMN."))
# Iterate through the albums and artists using a map call
album_lyrics <- kdot_albums %>%
mutate(tracks = map2(artist, album, genius_album))
@JosiahParry
JosiahParry / lyric_self_similarity
Created April 29, 2019 21:45
Example of using `calc_self_sim()` for self-similarity of song lyrics
library(genius)
library(tidytext)
library(tidyverse)
# get lyrics for album
since_96 <- genius_album("ALIX", "since 96")
# calculate self similarity by group (thank you dplyr v 0.8!!!)
self_sim_96 <- since_96 %>%
@JosiahParry
JosiahParry / track_audio_features.R
Created June 24, 2019 16:24
Create version of `get_track_audio_features()` which takes artist name and title.
# create function for getting song features
track_audio_features <- function(artist, title, type = "track") {
search_results <- search_spotify(paste(artist, title), type = type)
track_audio_feats <- get_track_audio_features(search_results$id[[1]]) %>%
dplyr::select(-id, -uri, -track_href, -analysis_url)
return(track_audio_feats)
}
# create a version of this function which can handle errors
@JosiahParry
JosiahParry / dem-debate-trends.R
Created July 2, 2019 01:31
code for exploring candidate google trends
library(httr)
library(jsonlite)
res <- GET("http://api.themoviedb.org/3/discover/movie?release_date.gte=2017-12-01&release_date.lte=2017-12-31&api_key=606aaffd7ca10f0b80804a1f0674e4e1&page=1") %>%
content("text") %>%
fromJSON()
int0_to_na <- function(x) {
---
title: "∑ { _my parts_ }"
output: github_document
---
```{r message=FALSE, warning=FALSE}
library(tidyverse)
terrorists <- googlesheets::gs_url("https://docs.google.com/spreadsheets/d/1LYQakIwGosibDHJKJqZgjM39qpSlp_gFG29zJ6paDAI/edit#gid=956062857") %>%
googlesheets::gs_read()
library(sqldf)
library(tidyverse)
polls <- read_csv("https://raw.githubusercontent.com/JosiahParry/r-4-campaigns/master/data/polls.csv")
sqldf("select candidate, count(*) as n
from polls
where points > 20
group by candidate
track_audio_features <- possibly(.f = {
function(artist, title, type = "track") {
search_results <- search_spotify(paste(artist, title), type = type)
track_audio_feats <- get_track_audio_features(search_results$id[[1]]) %>%
dplyr::select(-id, -uri, -track_href, -analysis_url)
return(track_audio_feats)
}}, otherwise = tibble())
@JosiahParry
JosiahParry / diceware.R
Created October 10, 2019 17:58
Simple function for generating diceware passwords
library(tidyverse)
dice_words <- read_tsv("https://www.eff.org/files/2016/07/18/eff_large_wordlist.txt",
col_names = c("dice_id", "dice_word"), col_types = "cc")
diceware <- function(n_words) {
map_dfr(1:n_words, ~tibble(dice_id = paste(sample(1:6, 5, replace = TRUE), collapse = ""))) %>%
left_join(dice_words)
}