Skip to content

Instantly share code, notes, and snippets.

View mine-cetinkaya-rundel's full-sized avatar

Mine Cetinkaya-Rundel mine-cetinkaya-rundel

View GitHub Profile
@mine-cetinkaya-rundel
mine-cetinkaya-rundel / life_locs.R
Last active November 19, 2018 13:35
Plotting and finding distances between places lived
# load packages ----------------------------------------------------------------
library(ggmap) # for geocoding cities, need v2.7 from https://github.com/dkahle/ggmap
library(fields) # for finding distance between two points
library(maps) # for world map
library(geosphere) # for connecting dots
# geocode cities lived ---------------------------------------------------------
ist <- geocode("Istanbul, Turkey")
nyc <- geocode("New York, NY, USA")
lax <- geocode("Los Angeles, CA, USA")
@mine-cetinkaya-rundel
mine-cetinkaya-rundel / mutate_if.R
Last active November 21, 2018 07:13
Use mutate_if to not repeat yourself
library(tidyverse)
# mutate -----------------------------------------------------------------------
iris %>%
mutate(
Sepal.Length_cat = ifelse(Sepal.Length < mean(Sepal.Length), "below mean", "at or above mean"),
Sepal.Width_cat = ifelse(Sepal.Width < mean(Sepal.Width), "below mean", "at or above mean"),
Petal.Length_cat = ifelse(Petal.Length < mean(Petal.Length), "below mean", "at or above mean"),
Petal.Width_cat = ifelse(Petal.Width < mean(Petal.Width), "below mean", "at or above mean")
) %>%
@mine-cetinkaya-rundel
mine-cetinkaya-rundel / lesson_emojis.Rmd
Last active November 23, 2018 19:16
Extracting emojis for each lesson
---
title: "Lesson emojis"
author: "Mine Çetinkaya-Rundel"
date: "11/21/2018"
output:
html_document:
highlight: pygments
theme: cerulean
---
---
title: "test"
output: html_vignette
---
```{r error=TRUE, comment = "#>", collapse = TRUE}
x
x()
```
library(tidyr)
library(dplyr, warn.conflicts = FALSE)
library(purrr)
x <- tibble(
v1 = list(NULL),
v2 = list("something"),
v3 = list(NULL)
)
@mine-cetinkaya-rundel
mine-cetinkaya-rundel / door.R
Last active September 21, 2019 22:50
Needed to put my name on my door, naturally I used #rstats for it
# load packages ----------------------------------------------------------------
library(tidyverse)
library(patchwork)
# m ----------------------------------------------------------------------------
m_df <- tribble(
~column, ~height,
"h1", 50,
@mine-cetinkaya-rundel
mine-cetinkaya-rundel / shiny-intro.R
Last active July 31, 2020 10:47
Intro walkthrough in Shiny app
library(shiny)
library(rintrojs)
ui <- fluidPage(
introjsUI(), # Must include UI
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
sliderInput(inputId = "bins",
@mine-cetinkaya-rundel
mine-cetinkaya-rundel / uncount.R
Created February 5, 2020 15:11
Example using tidyr::uncount()
# data source ------------------------------------------------------------------
# Are federal laws on gun ownership too strict? Not strict enough? Or just about right?
# http://www.surveyusa.com/client/PollReport.aspx?g=e2893631-b41f-40e1-a049-86e0849670ce
# load packages ----------------------------------------------------------------
library(tidyverse)
# frequency table --------------------------------------------------------------
freq_table <- tribble(
@mine-cetinkaya-rundel
mine-cetinkaya-rundel / theming_rprofile.R
Last active May 15, 2024 15:41
Add to your .Rprofile to change RStudio theme based on hour of the day (dark mode 8pm-6am, light mode 7am-7pm)
# theme options based on hour of day -------------------------------------------
# based on https://github.com/rstudio/rstudio/issues/1579
setHook("rstudio.sessionInit", function(chooseTheme) {
if (chooseTheme) {
if (as.numeric(format(as.POSIXct(Sys.time(), format = "%H:%M:%S"), "%H")) %in% c(0:5, 21:23)) {
if (rstudioapi::getThemeInfo()$editor != "Solarized Dark") rstudioapi::applyTheme("Solarized Dark")
} else {
if (rstudioapi::getThemeInfo()$editor != "Solarized Light") rstudioapi::applyTheme("Solarized Light")
}
}
@mine-cetinkaya-rundel
mine-cetinkaya-rundel / nyt-first-said.R
Created April 13, 2020 08:13
NYT First Said counts, labelling highest
library(rtweet)
library(tidyverse)
library(glue)
rt <- get_timeline(
user = "@NYT_first_said",
n = 18000
)
rt <- rt %>%