💁♀️
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
# Download data from here: https://taz.de/Proteste-gegen-Rechtsextremismus/!5988174/ | |
library(tidyverse) | |
# first version with police data | |
fl <- "~/Downloads/data-Q5MHN.csv" | |
dd <- read_csv(fl) |> | |
mutate(Ort = trimws(Ort), | |
date = as.Date(Datum, format = "%d.%m.%Y"), | |
pcount = `Teilnehmende laut Polizei`, |
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(ggplot2) | |
# the data | |
dd <- data.frame(x = c(0,3,6,9,10,14), | |
y = c(7,2,8,6,12,7)) | |
# OLS model | |
mod <- lm(y ~ x, dd) |
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(sf) | |
library(rmapshaper) | |
# Grab shapefiles, here from http://www.diva-gis.org/gdata | |
shps2 <- read_sf("GBR_adm/GBR_adm2.shp") | |
shps2s <- rmapshaper::ms_simplify(shps2) | |
outline <- st_union(shps2s) | |
outline_flat <- st_transform(outline, crs = 27700) | |
counties <- st_transform(shps2s, crs = 27700) | |
outline_5km_in <- st_buffer(outline_flat, dist = -5000) # 5km inland |
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
# Data from https://yg-infographics-data.s3-eu-west-1.amazonaws.com/ZAfbtHgj42wx4reHnaMtbBamoKdMxkFMpz4gnWMjiZCUAxDX66MsCB38K/2019_data/MRP_Tables_2019_Election_Public_Release.pdf | |
library(tidyverse) | |
theme_set(theme_minimal()) # no mouldy waffle | |
age <- "Age Con Lab LD Brexit Green SNP PC Other Turnout Fraction | |
18-25 22 53 13 2 5 4 0 1 52 8 | |
25-30 26 48 13 2 5 4 0 1 52 6 | |
30-35 30 43 15 2 4 4 0 1 57 7 | |
35-40 36 38 15 2 4 3 0 1 63 7 |
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
% Syllabus example by Will Lowe, ([email protected]) 2018 | |
% for the course POL 245 'Visualizing Data' (Part of the Freshman Scholars Institute) | |
% | |
% Compile it with xelatex (after you've inserted your own fonts) | |
\documentclass[11pt,letterpaper]{article} | |
\usepackage[margin=1in]{geometry} | |
\usepackage{marginnote} | |
\usepackage[dvipsnames]{xcolor} |
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
# install.packages(c("jsonlite", "dplyr")) | |
library(jsonlite) | |
library(dplyr) | |
json <- "https://www.sutterhealth.org/for-patients/chargemaster-2019.json" | |
cmr <- read_json(json) | |
gg <- bind_rows(lapply(cmr$CDM, as.data.frame)) | |
head(gg) # ok, now what... |
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) | |
page <- "https://www.newsobserver.com/news/politics-government/election/article100235752.html" | |
decreasers <- read_html(page) %>% # grab and parse the webpage | |
html_table %>% | |
pluck(1) %>% # first (and only) table | |
mutate(h2016 = parse_number(`2016 Hours`), # parse ugly number formats | |
h2012 = parse_number(`2012 Hours`), | |
County = toupper(County)) %>% | |
filter((h2016 - h2012) < 0) %>% |
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
```{r} | |
library(MonetDBLite) | |
library(RSQLite) | |
library(DBI) | |
library(dplyr) | |
library(microbenchmark) | |
library(ggplot2) | |
``` |
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
# convenience function for logit models | |
invlogit <- function(x){ 1 / (1 + exp(-x)) } | |
# some data cribbed from the R help pages | |
dd <- data.frame(ldose = rep(0:5, 2), | |
dead = c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16), | |
sex = rep(c("M", "F"), each = 6)) | |
# 30 trials in each row of which 'dead' beasties died | |
# fit a model |
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
fourfold_box <- function(bl_br_tl_tr, # values for bottom left, top right, etc. | |
cols = rep(rgb(0.8, 0.8, 0.8), 4), # default to grey fill | |
labels = NULL, # use these instead of bl, br, tl, and tr values | |
label.cols = rep("black", 4), # value colors | |
quadrant.labels = NULL, # default: don't label quadrants | |
quadrant.label.col = NULL, # default: "black" | |
small.min = 5, # center label in box unless it's smaller than this | |
small.label.mult = 1.5, # label this multiple of box side length further out | |
axis.lwd = 1, # crossbar thickness | |
axis.col = NULL, # default: "black" |
NewerOlder