Watts-College / cpp-529-spr-2023

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

Template for Labs#4-6 #18

Closed jasminacosta closed 6 months ago

jasminacosta commented 11 months ago

Hi @AntJam-Howell,

For the upcoming labs are we going to use templates or by using a new R script within the program? If there was a template for these labs I was unable to see them.

Thank you, Jasmin Acosta

jasminacosta commented 11 months ago

Also @AntJam-Howell,

I noticed when trying to replicate the steps in "Saving Your Dorling Cartogram" in a new R script I noticed that the package rgdal is supposedly non-existent when I searched up why it was not installing. In addition, I found this issue to be with the maptools package.

AntJam-Howell commented 11 months ago

@jasminacosta the RMD source script is provide for you to replicate each step. The Rmd link can be found on Module 3 (Link), and the RMD file can be downloaded from there, or directly from here (link)

jasminacosta commented 11 months ago

@AntJam-Howell For the Lab #4 we just replicate the steps from the lab #3 tutorial after we create the cartogram for our desired city? Or do we follow the steps on the lab 4 instructions? Because they slightly differ.

AntJam-Howell commented 11 months ago

@jasminacosta apologies, I didn't answer to your first question (I thought you were referring to Lab 3). yes, for lab 4 and after, you build your own RMD, which should be informed by the lab instructions and work from prior labs.

For lab 4, please pick San Diego for your MSA. I've updated this information on module 4. Other than that change, the instructions for Lab 4 (link) should be followed.

Best

jasminacosta commented 11 months ago

@AntJam-Howell

Okay, great!

My only question is now when I try to do the write to file step in creating the cartogram for some reason there is an error. I am not sure why because I am following the steps shown on "Saving Your Dorling Cartogram".

AntJam-Howell commented 11 months ago

Have you tried:

# WRITE TO FILE 

library( geojsonio )

phx_dorling <- spTransform( phx_dorling, CRS("+proj=longlat +datum=WGS84") )
geojson_write( phx_dorling, file="phx_dorling.geojson", geometry="polygon" )

Can save the dorling and load it in, as outlined in the following link (here)

jasminacosta commented 11 months ago

@AntJam-Howell The issue seems that it is saying it is the spTransform( ) function for some odd reason.

"Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘spTransform’ for signature ‘"sf", "CRS"’

I was having this issue also when it came to this step with the same function:

phx_dorling <- spTransform( phx_dorling, CRS("+proj=longlat +datum=WGS84") ) geojson_write( phx_dorling, file="phx_dorling.geojson", geometry="polygon" )

But when I changed both of the functions to st_transform it seemed to work?

Because after I was able to get the file SanDiego_dorling.geojson, but I do not understand how that loads to GitHub.

AntJam-Howell commented 11 months ago

@jasminacosta. ok, good to know. Since the original source code was written, it seems that the package update may have changed the function name from spTransofmr to st_transform.

jasminacosta commented 11 months ago

@AntJam-Howell Oh, that makes sense!

Thank you!

jasminacosta commented 11 months ago

@AntJam-Howell

Another question for San Diego on these steps:

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

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

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

Since San Diego is in one state is there something else that needs to be merged to be able to continue?

Thank you!

AntJam-Howell commented 11 months ago

@jasminacosta nope you can just use the first example, msp.pop1, tailoed to san diego. No need to get another state information or rbind the two.

jasminacosta commented 11 months ago

@AntJam-Howell

I tried that and for some reason it is merging the variables, but then there are zero observations showing?

AntJam-Howell commented 11 months ago

Make sure you have the right state id for california and county.fips for san diego.

AntJam-Howell commented 11 months ago

@jasminacosta

jasminacosta commented 11 months ago

@AntJam-Howell

When I did

these.msp <- crosswalk$msaname == "SAN DIEGO, CA" these.fips <- crosswalk$fipscounty[ these.msp ] these.fips <- na.omit( these.fips )

state.fips <- substr(these.fips, 1, 2)
county.fips <- substr(these.fips, 3, 5)

cbind( these.fips, state.fips, county.fips ) %>% pander()

I got the county.fips for San Diego and when I checked on the data table it matches and so does the state.fips for California.

But what I did notice was that the these.fips separated into the state.fips and county.fips numbers which are the same numbers but split? Is it supposed to do that or is the county.fip supposed to be the same number on the crosswalk data variable "fipscounty".

Because that is the thing I noticed right now how the different fips are from the these.fips but slipt?

AntJam-Howell commented 11 months ago

@jasminacosta It depends on how you use get_acs. the following should work based on your example:

sdg.pop <-
get_acs( geography = "tract", variables = "B01003_001",
     state = "06", county = county.fips, geometry = TRUE ) %>% 
     select( GEOID, estimate ) %>%
     rename( POP=estimate )
sdg.pop$GEOID<-sub('.', '', sdg.pop$GEOID)
jasminacosta commented 11 months ago

@AntJam-Howell

I tried your example and it finally merged correctly.

On the example that I was providing what was I doing wrong that it would not work? I want to make sure I learn from my mistakes.

Thank you!

jasminacosta commented 11 months ago

Hi @AntJam-Howell

I apologize for all the questions that I have been having for this lab, but I am having other issues.

On this part of the lab I was following the lab instructions, but I do not understand why the first part of the map works fine then when I add the next part (bb <- and tm_shape( msp_dorling, bbox=bb ) +) none of the points show.

Also, I had this same issue with the steps towards the end of the instructions and I do not understand why because I am following the steps that are shown.

tm_shape( msp_dorling ) + tm_polygons( size="POP", col="hinc12", n=7, style="quantile", palette="Spectral" )

bb <- st_bbox( c( xmin = -10451823, xmax = -10324525, ymax = 5639769, ymin = 5491665 ), crs = st_crs("+init=epsg:3395"))

tm_shape( msp_dorling, bbox=bb ) + tm_polygons( col="hinc12", n=10, style="quantile", palette="Spectral" ) + tm_layout( "Dorling Cartogram", title.position=c("right","top") )

msp_dorling$cluster3 <- as.factor( fit3$classification )

tmap_mode("plot") tmap_style("cobalt")

tm1 <- tm_shape( msp_dorling, bbox=bb ) + tm_polygons( col="cluster", palette="Accent" )

tm2 <- tm_shape( msp_dorling, bbox=bb ) + tm_polygons( col="cluster2", palette="Accent" )

tm3 <- tm_shape( msp_dorling, bbox=bb ) + tm_polygons( col="cluster3", palette="Accent" )

tmap_arrange( tm1, tm2, tm3 )

Thank you!

jasminacosta commented 11 months ago

@AntJam-Howell

AntJam-Howell commented 11 months ago

Hi try removing the bb command or pointing the bounding box to cover Dan Diego coordinates rather than the original city.

-- Anthony Howell Co-Director, Center for Technology, Data, and Society, Associate Professor, Public Policy Arizona State University

On Sun, Oct 29, 2023 at 4:06 PM jasminacosta @.***> wrote:

@AntJam-Howell https://urldefense.com/v3/__https://github.com/AntJam-Howell__;!!IKRxdwAv5BmarQ!Zw4J6FiYf3ZrXiTN0bVsB6Z71X1FXrGr1uAXCvZd9c-3Mycr2GVNVWK-4Qdphi5J55ZEsD6LyBoEA8VH1noXDEzX-VH2KQ$

— Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/Watts-College/cpp-529-spr-2023/issues/18*issuecomment-1784258122__;Iw!!IKRxdwAv5BmarQ!Zw4J6FiYf3ZrXiTN0bVsB6Z71X1FXrGr1uAXCvZd9c-3Mycr2GVNVWK-4Qdphi5J55ZEsD6LyBoEA8VH1noXDEx3QU8coQ$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AMK2Y75GKVONXH7SQZ56T4LYB3OPVAVCNFSM6AAAAAA6QICNE6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBUGI2TQMJSGI__;!!IKRxdwAv5BmarQ!Zw4J6FiYf3ZrXiTN0bVsB6Z71X1FXrGr1uAXCvZd9c-3Mycr2GVNVWK-4Qdphi5J55ZEsD6LyBoEA8VH1noXDEympB_Pog$ . You are receiving this because you were mentioned.Message ID: @.***>

jasminacosta commented 11 months ago

Hi @AntJam-Howell,

I removed the bb command and it worked!

How come the bb command was preventing it from working?

Thank you!!

AntJam-Howell commented 11 months ago

Coordinates are for different city.

-- Anthony Howell Co-Director, Center for Technology, Data, and Society, Associate Professor, Public Policy Arizona State University

On Sun, Oct 29, 2023 at 5:04 PM jasminacosta @.***> wrote:

Hi @AntJam-Howell https://urldefense.com/v3/__https://github.com/AntJam-Howell__;!!IKRxdwAv5BmarQ!YmRigQs0deA8QPOs2iTMD9GhABAjzWb1hoZ29RYIYDgsfg9dOdti6jVwWUGE0_keEQE7_Z_wGF0uvBVZwaJdSI8PyeeRaQ$ ,

I removed the bb command and it worked!

How come the bb command was preventing it from working?

Thank you!!

— Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/Watts-College/cpp-529-spr-2023/issues/18*issuecomment-1784282695__;Iw!!IKRxdwAv5BmarQ!YmRigQs0deA8QPOs2iTMD9GhABAjzWb1hoZ29RYIYDgsfg9dOdti6jVwWUGE0_keEQE7_Z_wGF0uvBVZwaJdSI_Y9Tbq3A$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AMK2Y74GFPBBY7APFWYCSJ3YB3VIBAVCNFSM6AAAAAA6QICNE6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBUGI4DENRZGU__;!!IKRxdwAv5BmarQ!YmRigQs0deA8QPOs2iTMD9GhABAjzWb1hoZ29RYIYDgsfg9dOdti6jVwWUGE0_keEQE7_Z_wGF0uvBVZwaJdSI-aMECP-w$ . You are receiving this because you were mentioned.Message ID: @.***>

jasminacosta commented 11 months ago

That makes sense.

Thank you!!