Skip to content

Instantly share code, notes, and snippets.

View luisDVA's full-sized avatar

Luis Verde Arregoitia luisDVA

View GitHub Profile
@luisDVA
luisDVA / untangleFunction.R
Created June 26, 2017 22:28
function to untangle header rows from a variable
## UNTANGLE FUNCTION
# Luis D. Verde (www.liomys.mx)
#' Pull interspersed header data into own column
#'
#' @param dframe The tibble or data frame with the interspersed headers in the first column
#' @param matchstring the string to match to pull the header rows (quoted character)
#' @param newCol name for the new variable that will be added to the df (quoted char)
#' @return a tbl or df (depending on the input) with the interspersed headers in their own column
#' @export
#'
@luisDVA
luisDVA / ggpupBV.R
Last active November 8, 2017 16:26
ggpup function modified to take in a vector of dog breeds to search for
# define function
# this code is just for fun and I do not have rights to the images on dogtime.com I just like dogs
ggpupBV <- function(ggplotObject,breedVector){
# required packages
require(dplyr)
require(jpeg)
require(grid)
require(gridExtra)
library(dplyr)
library(tidyr)
library(stringr)
library(purrr)
survey <- data_frame(ID= factor(seq.int(1,6,1)), answers=c("a","b,c","d,e","c,d","b,c,e","e"))
#survey %>%
map(survey$answers,strsplit,",")
library(dplyr)
library(tidyr)
survey <- data_frame(ID= factor(seq.int(1,6,1)), answers=c("a","b,c","d,e","c,d","b,c,e","e"))
survey %>% unnest(answers=strsplit(answers,","))
# A tibble: 11 x 2
@luisDVA
luisDVA / animatetopn.R
Created August 16, 2018 02:46
tidyverse demo animation
library(dplyr)
library(ggplot2)
library(gganimate)
library(tidyr)
library(stringr)
library(extrafont)
# set up data
dat <- data_frame(type=sort(rep(c("canine","feline","avian"),3)),
name=c("Sam","Austin","Squawk",
@luisDVA
luisDVA / shot-distances.R
Created January 5, 2019 21:38
animate b-ball shot distances
library(nbastatR) #install_github("abresler/nbastatR") if needed
# team shot chart for current season
hou <- teams_shots(teams = "Houston Rockets",
seasons = 2019)
library(dplyr) # because some functions conflict
last3games <- hou %>% select(idGame) %>%
unique() %>% top_n(3) %>% pull(idGame)
@luisDVA
luisDVA / shots-location.R
Created January 9, 2019 02:59
animate shot distances and locations side by side
library(nbastatR) # if needed install_github("abresler/nbastatR") if needed
# id for Devin Booker franchise scoring record vs Boston
phoBos <- 21601076
# team shot chart for 2017 season
phx <- teams_shots(teams = "Phoenix Suns",
seasons = 2017)
library(dplyr)
library(stringr)
@luisDVA
luisDVA / shot-richness.R
Created February 14, 2019 19:19
point proximity overlap for NBA shot chart data
# shot richness
# access shot chart data from the API
library(nbastatR)
# team shot chart stats
mavs <- teams_shots(
teams = "Dallas Mavericks",
seasons = 2019
)
hawks <- teams_shots(
@luisDVA
luisDVA / dog-ranks-2019.R
Last active April 29, 2019 21:05
do breed bump chart - new
library(purrr)
library(dplyr)
library(here)
library(magick)
library(fs)
library(stringr)
library(ggplot2)
library(ggimage)
library(tidyr)
library(hrbrthemes)
@luisDVA
luisDVA / dog-ranks-2020.R
Created May 13, 2020 05:14
Dog popularity bump chart
# 2020 (2019) AKC dog bump chart
library(ggplot2) # CRAN v3.3.0
library(ggbump) # CRAN v0.1.0
library(dplyr) # [github::tidyverse/dplyr] v0.8.99.9003
library(tidyr) # CRAN v1.0.3
library(ggimage) # CRAN v0.2.8
library(scico) # CRAN v1.1.0
library(extrafont) # CRAN v0.17
# make dataset