Skip to content

Instantly share code, notes, and snippets.

@gergness
Created April 6, 2018 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gergness/2623b2d65b1e07ec5096d8f56a9f9bfc to your computer and use it in GitHub Desktop.
Save gergness/2623b2d65b1e07ec5096d8f56a9f9bfc to your computer and use it in GitHub Desktop.
Hitting an error with transformr, not sure if I'm specifying it wrong though...
``` r
library(tidycensus)
library(rmapshaper)
library(cartogram)
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, proj.4 4.9.3
library(transformr)
library(ggplot2)
orig <- get_acs(
"state",
"B01001_001E",
year = 2016,
geometry = TRUE
) %>%
ms_simplify(keep = 0.01) %>% # Has warning but doesn't seem significant (get same error without it, and code goes more slowly)
st_transform(
paste0(
"+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 ",
"+x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"
)
)
scaled <- orig %>%
as('Spatial') %>%
cartogram("estimate", itermax = 3) %>%
st_as_sf()
#> Mean size error for iteration 1: 3.9712385095117
#> Mean size error for iteration 2: 2.87330686310866
#> Mean size error for iteration 3: 2.20310112924996
tweened <- tween_polygon(orig, scaled, "linear", 5, id = "GEOID")
#> Warning in is.na(polygon$x): is.na() applied to non-(list or vector) of
#> type 'NULL'
#> (there were a lot more of these warnings but I think they were all identical)
#> Error in insert_points(polygon$x, polygon$y, splits, n): Not compatible with requested type: [type=NULL; target=double].
```
Created on 2018-04-06 by the [reprex package](http://reprex.tidyverse.org) (v0.1.1.9000).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment