Skip to content

Instantly share code, notes, and snippets.

View EvaMaeRey's full-sized avatar

Gina Reynolds EvaMaeRey

View GitHub Profile
@EvaMaeRey
EvaMaeRey / ols_w_interaction_gg
Last active October 27, 2022 14:35
plot continuous and dummy w interaction term
compute_panel_ols_ind <- function(data, scales) {
model <- lm(y ~ x*indicator,
data = data)
data.frame(x = data$x,
y = model$fitted.values,
indicator = data$indicator)
}
@EvaMaeRey
EvaMaeRey / gist:6804e874f2d525460722cc8ab94499fc
Created October 26, 2022 13:45
continuous and indicator interaction
compute_panel_ols_ind <- function(data, scales) {
model <- lm(y ~ x*indicator,
data = data)
data.frame(x = data$x,
y = model$fitted.values,
indicator = data$indicator)
}
compute_panel_ols_ind <- function(data, scales) {
data$indicator = factor(indicator)
model <- lm(y ~ x + indicator,
data = data)
data.frame(x = data$x,
y = model$fitted.values,
indicator = data$indicator)
tabyl_flatten <- function(tabyl3d){
my_tibble <- tibble()
for (i in 1:length(tabyl3d)){
meta_name <- names(tabyl3d)[i]
my_tibble %>%
bind_rows(tabyl3d[[i]] %>%
@EvaMaeRey
EvaMaeRey / data_manipulation_rladies
Created November 13, 2019 00:11
for RLadies Denver
library(tidyverse)
library(gapminder)
gapminder %>% # data from package
filter(year == 2002) -> # filtering
gapminder_2002 # saving subset object
gapminder_2002 %>%
filter(continent == "Europe") ->
gapminder_2002_europe
@EvaMaeRey
EvaMaeRey / previous_commands.R
Created September 1, 2019 01:44 — forked from jimhester/previous_commands.R
Get the previous commands as a text string in RStudio
# RStudio overrides `history()`, `loadhistory()` and `savehistory()`,
# so they work somewhat differently than on the console version of R.
# This saves the current history to a temporary file then reads the last
# line of it (or more depending on the `n` argument)
#
# It does not handle multi-line commands, which would be more tricky to handle...
previous_commands <- function(n = 1) {
tf <- tempfile()
on.exit(unlink(tf))
savehistory(tf)
# Load the packages we’re going to be using:
# Alongside the usual stuff like tidyverse and magrittr, we’ll be using rvest for some web-scraping, jsonline to parse some JSON, and extrafont to load some nice custom fonts
needs(tidyverse, magrittr, rvest, jsonlite, extrafont)
# Before we go on, two things to note:
# First, on web scraping:
# You should always check the terms of the site you are extracting data from, to make sure scraping (often referred to as `crawling`) is not prohibited. One way to do this is to visit the website’s `robots.txt` page, and ensure that a) there is nothing explicitly stating that crawlers are not permitted, and b) ideally, the site simply states that all user agents are permitted (indicated by a line saying `User-Agect: *`). Both of those are the case for our use-case today (see https://www.ultimatetennisstatistics.com/robots.txt).
# And second, about those custom fonts:
library(rvest)
library(tidyverse)
library(stringr)
library(lubridate)
library(ggrepel)
pres_terms <-
read_html("https://www.presidentsusa.net/presvplist.html") %>%
html_nodes("table") %>%
pluck(1) %>%
@EvaMaeRey
EvaMaeRey / swe-regents.R
Created November 30, 2018 16:21 — forked from tannenberg/swe-regents.R
First try at web-scraping with rvest to plot age-tenure of the Regents of Sweden
#webscraping livrustkammaren to create a age-tenure graph of Swedish regents
#inspired by https://gist.github.com/acoppock
library(rvest)
library(tidyverse)
library(stringr)
library(lubridate)
library(ggrepel)
library(stringr)
@EvaMaeRey
EvaMaeRey / breaks_tutorial.Rmd
Created November 30, 2018 13:38
ggplot dplyr reveal breaking
---
title: "ggplot tutorial"
subtitle: "with Emi Tanaka's kunoichi + ninjutsu theme"
author: "<br><br>Gina Reynolds"
date: "<br>2018/09/16"
output:
xaringan::moon_reader:
chakra: libs/remark-latest.min.js
lib_dir: libs
css: ["kunoichi", "ninjutsu"]