Skip to content

Instantly share code, notes, and snippets.

library(tidycensus)
library(tidyverse)
options(tigris_use_cache = TRUE)
state_names <- c(state.name, "District of Columbia")
names(state_names) <- state_names
tictoc::tic()
age_maps <- map(state_names, ~{
@han-tun
han-tun / hi_mask_hvnp.geojson
Created March 2, 2021 17:33 — forked from segheysens/hi_mask_hvnp.geojson
Hawai'i masking layer that leaves out Hawai'i Volcanoes National Park
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# Download elevation tif from eg http://www.eea.europa.eu/data-and-maps/data/digital-elevation-model-of-europe
# First, convert elevation tif to a space delimited xyz (lng lat elevation) file
# $ gdal_translate -of XYZ elevation3x3.tif /tmp/file.xyz
df <- read_delim('/tmp/file.xyz', delim=' ', col_names=FALSE)
df %>%
mutate(X3 = na_if(X3, 0)) %>%
ggplot(aes(X1, -X2 + 20 * X3/max(X3, na.rm=TRUE), group=X2)) +
geom_line(size=0.05) +
@han-tun
han-tun / 2020-09-22_LA-RUG_Uncomfortable-data.R
Created September 23, 2020 23:59 — forked from alistaire47/2020-09-22_LA-RUG_Uncomfortable-data.R
2020-09-22 LA R Users Group talk: Uncomfortable data
#' Uncomfortable data
#' LA R Users Group
#' 2020-09-22
#' Edward Visel
#' Setup
library(tidyverse)
path <- '/tmp/nycflights13/flights.csv'
@han-tun
han-tun / index.html
Created September 14, 2020 02:09 — forked from dianaow/index.html
Using deck.gl with Mapbox GL JS (Method 2): Using deck.gl layers as custom Mapbox layers
<html>
<head>
<title>Using deck.gl with Mapbox GL JS (Method 2)</title>
<script src="https://d3js.org/d3.v5.min.js" type="text/javascript"></script>
<script src="https://unpkg.com/deck.gl@latest/dist.min.js"></script>
<script src="https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.js"></script>
<link href="https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.css" rel="stylesheet" />
<style type="text/css">
body {
@han-tun
han-tun / index.html
Created September 14, 2020 02:09 — forked from dianaow/index.html
Using deck.gl with Mapbox GL JS (Method 2): Using deck.gl layers as custom Mapbox layers
<html>
<head>
<title>Using deck.gl with Mapbox GL JS (Method 2)</title>
<script src="https://d3js.org/d3.v5.min.js" type="text/javascript"></script>
<script src="https://unpkg.com/deck.gl@latest/dist.min.js"></script>
<script src="https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.js"></script>
<link href="https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.css" rel="stylesheet" />
<style type="text/css">
body {
@han-tun
han-tun / index.html
Created September 14, 2020 02:08 — forked from dianaow/index.html
Using deck.gl with Mapbox GL JS (Method 1): Deck canvas overlay
<html>
<head>
<title>deck.gl ScatterplotLayer Example</title>
<script src="https://d3js.org/d3.v5.min.js" type="text/javascript"></script>
<script src="https://unpkg.com/deck.gl@latest/dist.min.js"></script>
<script src="https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.js"></script>
<link href="https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.css" rel="stylesheet" />
<style type="text/css">
body {
library(geofacet)
library(ggplot2)
# original plot
ggplot(election, aes(candidate, votes / 1000000, fill = candidate)) +
geom_col() +
scale_fill_manual(values = c("#4e79a7", "#e15759", "#59a14f")) +
facet_geo(~ state, grid = "us_state_grid2") +
coord_flip() +
ylab("Votes (millions)")
---
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r message=FALSE, warning=FALSE}
library(tidyverse)