Watts-College / cpp-529-spr-2022

https://watts-college.github.io/cpp-529-spr-2022/
0 stars 2 forks source link

LAB 04 Step 4 Issue #15

Open JPRayes opened 2 years ago

JPRayes commented 2 years ago

Another issue...

So I'm trying to Transform the Shapefile into A Dorling Cartogram

Here's my code:

convert sf map object to an sp version

den.sp <- as_Spatial( den ) class( den.sp )

Here's the error:

Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'addAttrToGeom': subscript out of bounds

All other prior code appears to be working:

Here's the code leading up to the error:

URL <- "https://github.com/DS4PS/cpp-529-master/raw/master/data/ltdb_std_2010_sample.rds" census.dat <- readRDS(gzcon(url( URL )))

can merge an sf object and data.frame

den <- merge( den.pop, census.dat, by.x="GEOID", by.y="tractid" )

make sure there are no empty polygons

den <- den[ ! st_is_empty(den) , ]

JasonSills commented 2 years ago

Hi @JPRayes ,

You are working with a state with a code that starts with "0". You will need to convert the data to numeric so it recognizes the need for a "0". For example a state with a code of "04" is "4" in the dataset. Setting it as numeric assures it is a "04".

Use this code (this is for Jackson, Mississippi, be sure to update with your code for Denver): can merge an sf object and data.frame jax.pop$GEOID <- as.numeric(jax.pop$GEOID) # this makes the data numeric jax <- merge( jax.pop, census.dat, by.x="GEOID", by.y="tractid" )

make sure there are no empty polygons jax <- jax[ ! st_is_empty( jax ) , ] head(jax)

JPRayes commented 2 years ago

@JasonSills Thank you! and thanks for covering it in the review session.