This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tabyl_flatten <- function(tabyl3d){ | |
my_tibble <- tibble() | |
for (i in 1:length(tabyl3d)){ | |
meta_name <- names(tabyl3d)[i] | |
my_tibble %>% | |
bind_rows(tabyl3d[[i]] %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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"] |
NewerOlder