Skip to content

Instantly share code, notes, and snippets.

View yjunechoe's full-sized avatar
🐣

June Choe yjunechoe

🐣
View GitHub Profile
# somewhat hackish solution to:
# https://twitter.com/EamonCaddigan/status/646759751242620928
# based mostly on copy/pasting from ggplot2 geom_violin source:
# https://github.com/hadley/ggplot2/blob/master/R/geom-violin.r
library(ggplot2)
library(dplyr)
"%||%" <- function(a, b) {
@yjunechoe
yjunechoe / P_lab_ggplot2.Rmd
Last active December 8, 2021 10:22
{ggplot2} flipbook for Phonetics Lab (10/23/20) - style guide & showcasing
---
title: "Visualizing Data (in R)"
subtitle: "An opinionated style guide"
author: "<br><br>June Choe<br><br>Phonetics Lab"
date: '2020-10-23'
output:
xaringan::moon_reader:
lib_dir: libs
css: [default, hygge, ninjutsu]
nature:
@yjunechoe
yjunechoe / eyetracking_gganimate
Last active October 23, 2020 05:03
gganimate gif for visual-world eye-tracking data from de Carvalho et al. (2017)
read_csv("https://yjunechoe.netlify.app/data/CarvalhoEtAl_2017.csv", col_types = cols(reveal_time = col_integer())) %>%
ggplot(aes(Time, Proportion)) +
geom_ribbon(
aes(ymin = YMin, ymax = YMax, group = Condition),
color = "grey70",
fill = "grey80",
alpha = .3
) +
geom_point(
aes(color = Condition, group = Condition)
@yjunechoe
yjunechoe / split_track.R
Last active October 21, 2020 18:49
To be used with transition_reveal() when you have your own column for reveal time
library(tidyverse)
library(gganimate)
library(rlang)
split_track <- function(df, grouping_var, tracked_along, ..., tracked_groups = ".all") {
region <- df %>%
filter(...) %>%
group_by({{ grouping_var }}) %>%
mutate(row_id = 1:n()) %>%
@yjunechoe
yjunechoe / colorbot_tweets.R
Last active October 22, 2020 16:02
1000 tweets from @everycolorbot
# https://pbs.twimg.com/media/Ek8VZFEVgAAHZM_?format=png&name=4096x4096
colortweets <- rtweet::get_timeline("everycolorbot", 1000)
colortweets_df <- colortweets %>%
select(created_at, text, favorite_count) %>%
mutate(
hour = lubridate::hour(created_at),
hex = paste0("#", str_extract(text, "(?<=0x).*(?= )"))
)
@yjunechoe
yjunechoe / bivariate_unif_means_anim.R
Last active October 26, 2020 22:47
Tracking the mean through 100 samples form bivariate uniform distribution ~ unif(0, 1)
library(tidyverse)
library(slider)
library(gganimate)
points <- tibble(
id = 1:100,
x = runif(100),
y = runif(100),
time = 1:100,
size = 2,
library(tidyverse)
library(patchwork)
library(magick)
df <- tribble(
~Condition, ~Referent, ~Accuracy,
"Primacy", "Single", 0.63,
"Primacy", "Primacy", 0.59,
"Recency", "Single", 0.63,
"Recency", "Recency", 0.5,
@yjunechoe
yjunechoe / Kernel estimation animation
Created February 20, 2021 01:33
Recreation of the animation of kernel estimation from "Visualizing How a Kernel Draws a Smooth Line" - https://www.walker-harrison.com/posts/2021-02-13-visualizing-how-a-kernel-draws-a-smooth-line/
## Code by Walker Harrison @walkwearscrocs
## From https://www.walker-harrison.com/posts/2021-02-13-visualizing-how-a-kernel-draws-a-smooth-line/
library(tidyverse)
theme_set(theme_bw())
set.seed(0)
n <- 100
x <- runif(n, 0, 4*pi)
@yjunechoe
yjunechoe / chrome_anim.R
Created March 12, 2021 00:20
Draw the Chrome icon from Font Awesome using {string2path} - https://github.com/yutannihilation/string2path
library(dplyr)
library(ggplot2)
library(gganimate)
# Path to Font Awesome 5 Brands ttf file
fa_brands <- paste0(
Sys.getenv("FONT_PATH"),
"Font-Awesome-5-Brands-Regular-400.ttf"
)
library(ggplot2)
library(ggfx)
library(ragg)
ggplot(NULL) +
as_reference(
geom_rect(
aes(xmin = -1, xmax = 1, ymin = -.6, ymax = -.6 + 1.2 * (8/60)),
fill = '#961A1F',
),