Skip to content

Instantly share code, notes, and snippets.

View chris-prener's full-sized avatar

Chris Prener chris-prener

View GitHub Profile
@jennybc
jennybc / 2020-03-29_sane-legend.R
Created March 30, 2020 05:21
Make the legend order = data order, with forcats::fct_reorder2()
library(tidyverse)
library(patchwork)
dat_wide <- tibble(
x = 1:3,
top = c(4.5, 4, 5.5),
middle = c(4, 4.75, 5),
bottom = c(3.5, 3.75, 4.5)
)
@jshannon75
jshannon75 / meancenterweights
Created November 25, 2019 01:36
Calculating state mean centers in R
library(tidyverse)
library(sf)
#Join population data to tract boundaries and convert to point coordinates
tractdata<-read_csv("nhgis0105_2017_tract_racepov.csv") #Data on population downloaded from NHGIS
tracts<-st_read("nhgis0101_shapefile_tl2017_us_tract_2017/US_tract_2017.shp",stringsAsFactors=FALSE) %>% #Tract boundaries downloaded from NHGIS
st_transform(4326)
tract_center<-tracts %>%
st_centroid() %>%
st_coordinates() %>%