Skip to content

Instantly share code, notes, and snippets.

Avatar

Claus Wilke clauswilke

View GitHub Profile
@clauswilke
clauswilke / CFR.Rmd
Created Mar 17, 2020
COVID-19 Case Fatality Rate (CFR) by age
View CFR.Rmd
---
title: "COVID-19 Case Fatality Rate (CFR) by age"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
```
View rstudio::conf2019 code
# Code for presentation at rstudio::conf2019
# Slides:
# https://docs.google.com/presentation/d/1zMuBSADaxdFnosOPWJNA10DaxGEheW6gDxqEPYAuado/edit?usp=sharing
# Setup -------------------------------------------------------------------
library(ggplot2)
library(gganimate)
library(ungeviz)
library(mgcv)
@clauswilke
clauswilke / contour_lines.cpp
Last active Dec 27, 2018
Contour lines and bands example for R, written in Rcpp
View contour_lines.cpp
// This file implements the 2D isoline and isoband algorithms described
// here: https://en.wikipedia.org/wiki/Marching_squares
// Written by Claus O. Wilke
#include <Rcpp.h>
using namespace Rcpp;
#include <iostream>
#include <vector>
#include <utility> // for pair
View Goode homolosine choropleth
library(tidyverse)
library(sf)
# Development version of colorspace is needed. Install via:
# install.packages("colorspace", repos = "http://R-Forge.R-project.org")
library(colorspace)
crs_goode <- "+proj=igh"
world_goode <- st_as_sf(rworldmap::getMap(resolution = "low")) %>%
View world_maps.Rmd
---
title: "World maps"
output:
html_document:
df_print: paged
---
```{r echo = FALSE, message = FALSE}
library(tidyverse)
library(sf)
View Alaska_Hawaii_animation.R
library(sf)
library(dplyr)
library(ggplot2)
library(gganimate) # needs development version from github
# helper function to place a geometric object at a desired position
# and scale
place_geometry <- function(geometry, position, scale = 1) {
(geometry - st_centroid(geometry)) * scale +
st_sfc(st_point(position))
@clauswilke
clauswilke / 2018-06_cleaned.csv
Created Jul 29, 2018
Visualizing a high-dimensional macroeconomics time series via PCA
View 2018-06_cleaned.csv
We can't make this file beautiful and searchable because it's too large.
sasdate,RPI,W875RX1,DPCERA3M086SBEA,CMRMTSPLx,RETAILx,INDPRO,IPFPNSS,IPFINAL,IPCONGD,IPDCONGD,IPNCONGD,IPBUSEQ,IPMAT,IPDMAT,IPNMAT,IPMANSICS,IPB51222S,IPFUELS,CUMFNS,HWI,HWIURATIO,CLF16OV,CE16OV,UNRATE,UEMPMEAN,UEMPLT5,UEMP5TO14,UEMP15OV,UEMP15T26,UEMP27OV,CLAIMSx,PAYEMS,USGOOD,CES1021000001,USCONS,MANEMP,DMANEMP,NDMANEMP,SRVPRD,USTPU,USWTRADE,USTRADE,USFIRE,USGOVT,CES0600000007,AWOTMAN,AWHMAN,HOUST,HOUSTNE,HOUSTMW,HOUSTS,HOUSTW,PERMIT,PERMITNE,PERMITMW,PERMITS,PERMITW,AMDMNOx,AMDMUOx,BUSINVx,ISRATIOx,M1SL,M2SL,M2REAL,AMBSL,TOTRESNS,NONBORRES,BUSLOANS,REALLN,NONREVSL,CONSPI,S&P 500,S&P: indust,S&P div yield,S&P PE ratio,FEDFUNDS,CP3Mx,TB3MS,TB6MS,GS1,GS5,GS10,AAA,BAA,COMPAPFFx,TB3SMFFM,TB6SMFFM,T1YFFM,T5YFFM,T10YFFM,AAAFFM,BAAFFM,EXSZUSx,EXJPUSx,EXUSUKx,EXCAUSx,WPSFD49207,WPSFD49502,WPSID61,WPSID62,OILPRICEx,PPICMM,CPIAUCSL,CPIAPPSL,CPITRNSL,CPIMEDSL,CUSR0000SAC,CUSR0000SAD,CUSR0000SAS,CPIULFSL,CUSR0000SA0L2,CUSR0000SA0L5,PCEPI,DDURRG3M086SBEA,DNDGRG3M086SBEA,DSERRG3M086SBEA,CES0600000008,CES2000000008,CES300
View VSUP cartogram
library(ggplot2)
library(multiscales)
colors <- scales::colour_ramp(
colors = c(red = "#AC202F", purple = "#740280", blue = "#2265A3")
)((0:7)/7)
types <- c(
'Natural state geometry',
'Cartogram weigted by electoral votes'
@clauswilke
clauswilke / correlation_matrix.R
Last active May 12, 2020
Tidyverse approach to calculating and plotting correlation matrices
View correlation_matrix.R
library(dplyr)
library(tidyr)
library(purrr)
library(ggplot2)
library(colorspace)
# data to analyze
data <- select(MASS::fgl, -type, -RI, -Si)
# cluster
View animate_labels.R
library(ggplot2) # requires 2.3.0
library(purrr)
make_plot <- function(frame) {
ggplot(mtcars, aes(mpg, hp, color = factor(cyl))) +
geom_point() +
scale_color_brewer(
palette = 2, type = "qual", name = "cyl",
guide = guide_legend(
direction = "horizontal",