Skip to content

Instantly share code, notes, and snippets.

View sharlagelfand's full-sized avatar
💅
#rstats

Sharla Gelfand sharlagelfand

💅
#rstats
View GitHub Profile
library(ggplot2)
library(dplyr)
library(tidytext)
nintendo <- tribble(
~console, ~sales_type, ~sales_million,
"Nintendo Switch", "Hardware", 52.48,
"Nintendo Switch", "Software", 310.65,
"Nintendo 3DS", "Hardware", 75.71,
"Nintendo 3DS", "Software", 382.22,
@sharlagelfand
sharlagelfand / fsa_cma.R
Created May 9, 2023 22:20
FSAs in Vancouver CMA
# Get v0.5.6 of cancensus for FSA geography
# remotes::install_github("mountainMath/cancensus", ref = "v0.5.6")
library(cancensus)
library(tongfen)
library(dplyr)
library(sf)
library(ggplot2)
dataset <- "CA21"
I am attesting that this GitHub handle sharlagelfand is linked to the Tezos account tz1eRpQwGZrxvot1hVTgSdAEg6KU23q6h9Jg for tzprofiles
sig:edsigtp4UvziQ5wFYXgk8GuPNWGmf7ekasd8DH11jrfJEG92sRsSJa2vw6HV3gFVKtWL1M2sdmsjciytUGCMciFhpzfFP7D1Bks
sharla_diff <- function(df, expected_df) {
data_as_expected <- dplyr::all_equal(expected_df, df)
if (!isTRUE(data_as_expected)) {
data_diffs <- janitor::compare_df_cols(expected_df, df)
cols_mismatch <- dplyr::filter(data_diffs, is.na(expected_df) | is.na(df))
extra_cols <- cols_mismatch %>%
dplyr::filter(is.na(expected_df)) %>%
@sharlagelfand
sharlagelfand / labeller
Created March 26, 2021 16:00
Demonstrating the usage of the argument `labeller = label_wrap_gen()` in the ggplot2 function facet_wrap()
library(ggplot2)
library(tibble)
df <- tribble(
~x, ~y, ~label,
1, 2, "A super long label oh god how am I going to deal with this",
2, 1, "A shorter one"
)
# Default - text is cut off
@sharlagelfand
sharlagelfand / gist:7245d2293b45399dec9a7f94dc1799ce
Created February 4, 2021 21:33
please clean my data for me
library(dplyr)
library(tidyr)
initial <- tibble(
name = c("name_1", "name_2"),
value = list(
tibble(name = c("subname_1", "subname_2"), value = c(1, 2)),
tibble(name = c("subname_3", "subname_4"), value = c(3, 4))
)
)
@sharlagelfand
sharlagelfand / rilo kiley albums as ggkeyboard
Created December 18, 2020 21:30
rilo kiley albums as ggkeyboard
library(ggkeyboard)
library(ggplot2)
extrafont::loadfonts()
# More adventurous
ggkeyboard(tkl,
palette = c(
background = "#FFFFFF",
keyboard = "#272530",
library(rtweet)
library(dplyr)
library(tidytext)
library(stringr)
library(ggplot2)
library(ggwordcloud)
dc <- search_tweets(
"datacamp",
n = 1000, include_rts = FALSE
@sharlagelfand
sharlagelfand / gist:165825299f9a28c768c4cc4b55471919
Created May 17, 2020 19:33
{gt} x #TwoFunctionsMostDays wrapup
library(gt)
library(tibble)
acnh_bugs_n <- tribble(
~name, ~price, ~location, ~time, ~months, ~image,
"Yellow butterfly", 160, "Flying", "4 AM - 7 PM", "Mar - Jun, Sep - Oct", "https://vignette.wikia.nocookie.net/animalcrossing/images/f/fa/NH-Icon-yellowbutterfly.png",
"Peacock butterfly", 2500, "Flying by Hybrid Flowers", "4 AM - 7 PM", "Mar - June", "https://vignette.wikia.nocookie.net/animalcrossing/images/8/8f/NH-Icon-peacockbutterfly.png",
"Atlas moth", 3000, "On Trees", "7 PM - 4 AM", "Apr - Sep", "https://vignette.wikia.nocookie.net/animalcrossing/images/6/6a/NH-Icon-atlasmoth.png",
"Centipede", 300, "Hitting Rocks", "4 PM - 11 PM", "Sep - June", "https://vignette.wikia.nocookie.net/animalcrossing/images/3/30/NH-Icon-centipede.png",
"Snail", 250, "On Rocks and Bushes (Rain) ", "All Day", "Jan - Dec", "https://vignette.wikia.nocookie.net/animalcrossing/images/b/b1/NH-Icon-snail.png",
library(tidyr)
library(dplyr)
library(forcats)
library(purrr)
library(magick)
items <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-05-05/items.csv")
flowers <- items %>%
filter(category == "Flowers") %>%