Skip to content

Instantly share code, notes, and snippets.

View luisDVA's full-sized avatar

Luis Verde Arregoitia luisDVA

View GitHub Profile
@luisDVA
luisDVA / regex-01_understanding-regex.R
Last active November 24, 2020 20:07
Understanding a regular expression - your turn: Solutions
## %######################################################%##
# #
#### Understanding a regular expression - your turn ####
# #
## %######################################################%##
# Write regular expressions to match:
# Test with stringr, regexplain, or a web-based regex tester
# "cute, cuuute, cuuuuuute, and cuuuuuuuuute"
library(ggplot2)
library(dplyr)
# datos internos que vienen con ggplot2
animals <-
msleep %>% slice_max(sleep_rem, n = 30) %>% # seleccionando top 30
ggplot(aes(x = forcats::fct_reorder(name, sleep_total), y = sleep_total, label = name)) +
geom_bar(stat = "identity") + xlab("") +
geom_text(nudge_y = 2, hjust = 0) +
theme(
@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
@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 / 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 / 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-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 / 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",
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
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,",")