Watts-College / cpp-529-fall-2021

https://watts-college.github.io/cpp-529-fall-2021/
0 stars 0 forks source link

Lab04 - issues with adding a third state (msp.pop3) #8

Open trioptre opened 3 years ago

trioptre commented 3 years ago

@AntJam-Howell :

The MSA I chose has three states (in the lab walkthrough/example, there are two states MN/WI).

If I add a msp.pop3 as shown below and rbind all three msps, I get an error "Error in t[, i] : incorrect number of dimensions" when I try to run all of the chunks:

Code Chunk 1:

msp.pop <-
get_acs( geography = "tract", variables = "B01003_001",
         state = "21", county = county.fips[state.fips=="21"], geometry = TRUE ) %>% 
         select( GEOID, estimate ) %>%
         rename( POP=estimate )

msp.pop2 <-
get_acs( geography = "tract", variables = "B01003_001",
         state = "39", county = county.fips[state.fips=="39"], geometry = TRUE ) %>%
         select( GEOID, estimate ) %>%
         rename( POP=estimate )

msp.pop3 <-
get_acs( geography = "tract", variables = "B01003_001",
         state = "54", county = county.fips[state.fips=="54"], geometry = TRUE ) %>%
         select( GEOID, estimate ) %>%
         rename( POP=estimate )

msp.pop <- rbind( msp.pop1, msp.pop2, msp.pop3 )

Code chunk 2 (truncated):


for( i in 1:num.groups )
{
  z <- t[,i]
  plot( rep(1,30), 1:30, bty="n", xlim=c(-75,100), 
        type="n", xaxt="n", yaxt="n",
        xlab="Percentile", ylab="",
        main=paste("GROUP",i) )
  abline( v=seq(0,100,25), lty=3, lwd=1.5, col="gray90" )
  segments( y0=1:30, x0=0, x1=100, col="gray70", lwd=2 )
  text( -0.2, 1:30, data.dictionary$VARIABLE[-1], cex=0.85, pos=2 )
  points( z, 1:30, pch=19, col="firebrick", cex=1.5 )
  axis( side=1, at=c(0,50,100), col.axis="gray", col="gray" )
}

Any suggestions?

Thanks!

AntJam-Howell commented 3 years ago

@trioptre One issue is that the rename command has a dependency conflict with another package, which keeps the pop=estimate to work properly. Try to add dplyr:: before rename() each time and see if that works. That is, change rename( POP=estimate ) to dplyr::rename( POP=estimate ).

If that doesn't work, send me your RMD file to anthony.howell@asu.edu.

trioptre commented 2 years ago

@AntJam-Howell - I wasn't able to get your suggestion to work, so I submitted Lab 4 with a different MSA that only covered two states (as in the lab 4 overview example). I do have a couple of follow-up questions, though;

What is the name of the other package?

Why would the pop=estimate work properly for two states, but not three states?

AntJam-Howell commented 2 years ago

Hi @trioptre,

Smart to use an MSA with only 1 state, it can get a bit more complicated with 2 or more states. It wouldn't matter if it is 1, 2, or 3 states. If you look at the resulting dataframe after you were doing the pop=estimate, did you see that the estimate column did not show up correctly? After you use dplyr::rename(pop=estimate) it does show up properly? At least in my case running on my computer, that is what I noticed, but it could depend on what version of specific packages you are using on your own computer. Not sure what other package was causing the problem though.