DS4PS / cpp-529-spr-2021

Course shell for CPP 529 Community Analytics
http://ds4ps.org/cpp-529-spr-2021/
2 stars 0 forks source link

Choropleth Map not showing up #33

Open voznyuky opened 7 months ago

voznyuky commented 7 months ago

@AntJam-Howell

This is what I have so far:


# DATA STEPS 

# load dorling cartogram from github
# map already contains census data and groups from clustering 

sd <- geojson_read( x="/Users/yelenavoznyuk/Documents/ASU Grad School/PAF 516/Final Projectsd_dorling.geojson",  what="sp" )

# reproject the map 
sd2 <- spTransform( sd, CRS("+init=epsg:3395") )

# convert the sp map format to 
# an sf (simple features) format:
# ggmap requires the sf format
sd.sf <- st_as_sf( sd2 )

# separate out the data frame from the map
d <- as.data.frame( sd.sf )
renderPlot({

# split the selected variable into deciles 

get_data <- 
  reactive({
             sd.sf <- 
             sd.sf %>% 
             mutate( q = ntile( get(input$demographics), 10 ) )  
          })

ggplot( get_data() ) +
    geom_sf( aes( fill = q ), color=NA ) +
    coord_sf( datum=NA ) +
    labs( title = paste0( "Choropleth of Select Demographics: ", toupper(input$demographics) ),
          caption = "Source: Harmonized Census Files",
          fill = "Population Deciles" ) +
    scale_fill_gradientn( colours=rev(ocean.balance(10)), guide = "colourbar" ) + 
    xlim( xmin = -12519146, xmax = -12421368 ) + 
    ylim( ymin = 3899074, ymax = 3965924 )

})

It shows the buttons and updated labels but no map. I found that this came up in a previous class, similar issue: https://github.com/DS4PS/cpp-529-spr-2021/issues/19#issuecomment-826006011

AntJam-Howell commented 7 months ago

Hi, It appears the coordinate settings are not set properly to capture the map. Is your xmin, xmax, ymin, ymax coordinates correct for San Diego?

voznyuky commented 7 months ago

@AntJam-Howell I am not sure how to find the coordinates, I've watched the video from labe 3 (I believe it was) but I work on a Mac and it doesn't work for me. Do you have a good tool/site you can recommend?

AntJam-Howell commented 7 months ago

Yes, if on a mac, you can google bounding box location and find an opensource website bbox finder (Link http://bboxfinder.com/#0.000000,0.000000,0.000000,0.000000). You can focus in on San Diego and define your own bounding box and then update your boundaries.

On Thu, Apr 18, 2024 at 3:06 PM voznyuky @.***> wrote:

@AntJam-Howell https://urldefense.com/v3/__https://github.com/AntJam-Howell__;!!IKRxdwAv5BmarQ!ZjR1feU8cREbv1n-05MmiHel2jNGskVTY9GYwr9cFOhfBfpRpQbasn3YAqhhlZT4VLK-6NqWPBGY03PMtfjmGXeF9jqCZA$ I am not sure how to find the coordinates, I've watched the video from labe 3 (I believe it was) but I work on a Mac and it doesn't work for me. Do you have a good tool/site you can recommend?

— Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/DS4PS/cpp-529-spr-2021/issues/33*issuecomment-2065408537__;Iw!!IKRxdwAv5BmarQ!ZjR1feU8cREbv1n-05MmiHel2jNGskVTY9GYwr9cFOhfBfpRpQbasn3YAqhhlZT4VLK-6NqWPBGY03PMtfjmGXfEbel2Ew$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AMK2Y75W3Y2PWDJDIYD32RDY6A7XPAVCNFSM6AAAAABGMMUXHCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRVGQYDQNJTG4__;!!IKRxdwAv5BmarQ!ZjR1feU8cREbv1n-05MmiHel2jNGskVTY9GYwr9cFOhfBfpRpQbasn3YAqhhlZT4VLK-6NqWPBGY03PMtfjmGXd1P3nl3g$ . You are receiving this because you were mentioned.Message ID: @.***>

-- Anthony Howell (Website https://anthonyhowell.netlify.app/) Director, Center on Technology, Data, and Society, Associate Professor, Public Policy Arizona State University

voznyuky commented 7 months ago

@AntJam-Howell That was it! Thank you. I tried another site but it wasn't giving me the coordinates useful in R.

AntJam-Howell commented 7 months ago

Great!

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

On Thu, Apr 18, 2024 at 12:45 PM voznyuky @.***> wrote:

@AntJam-Howell https://urldefense.com/v3/__https://github.com/AntJam-Howell__;!!IKRxdwAv5BmarQ!YPHiOImpxsVCR_X-JgS0rfHgV6Scz7L2PumYt-ZutoUl1HB4FXuPEw5rrRXUs_SKl028d-k9-p_m2owDyCNo5ey_ep4O_g$ That was it! Thank you. I tried another site but it wasn't giving me the coordinates useful in R.

— Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/DS4PS/cpp-529-spr-2021/issues/33*issuecomment-2065445058__;Iw!!IKRxdwAv5BmarQ!YPHiOImpxsVCR_X-JgS0rfHgV6Scz7L2PumYt-ZutoUl1HB4FXuPEw5rrRXUs_SKl028d-k9-p_m2owDyCNo5ezb0UewKQ$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AMK2Y773XAWFD3F7GOZSK4TY6BEINAVCNFSM6AAAAABGMMUXHCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRVGQ2DKMBVHA__;!!IKRxdwAv5BmarQ!YPHiOImpxsVCR_X-JgS0rfHgV6Scz7L2PumYt-ZutoUl1HB4FXuPEw5rrRXUs_SKl028d-k9-p_m2owDyCNo5ezLsmLPHg$ . You are receiving this because you were mentioned.Message ID: @.***>

voznyuky commented 7 months ago

@AntJam-Howell I have a few more questions I am hoping you can help me out with.

I am in the 'NH Changes 00-10' and the following code is not working:

Median Home Values


renderPlot({

# split the selected variable into deciles 

get_data <- 
  reactive({
             sd.sf <- 
             sd.sf %>% 
             mutate( q = ntile( get(input$home.value), 10 ) )  
          })

ggplot( get_data() ) +
    geom_sf( aes( fill = q ), color=NA ) +
    coord_sf( datum=NA ) +
    labs( title = paste0( "Choropleth of Select Demographics: ", toupper(input$demographics) ),
          caption = "Source: Harmonized Census Files",
          fill = "Population Deciles" ) +
    scale_fill_gradientn( colours=rev(ocean.balance(10)), guide = "colourbar" ) + 
    xlim( xmin = -13152029, xmax = -12931890 ) + 
    ylim( ymin = 3812996, ymax = 3932084 )

})

I suspect is it the object 'home.value'. When I tried 'get(input$demographics' it worked. I am wondering if my dorling is not correct?

I am having a similar problem with 'Drivers of Change' it is telling me 'object 'mhmval12' not found'. If i was to put in another object, such as 'PNHWHT12' it worked. This is why I think it might be something with my dorling file.

Thank you in advance.

AntJam-Howell commented 7 months ago

Can you email me your rmd file used to create your dorling?

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

On Thu, Apr 18, 2024 at 1:44 PM voznyuky @.***> wrote:

@AntJam-Howell https://urldefense.com/v3/__https://github.com/AntJam-Howell__;!!IKRxdwAv5BmarQ!fjLDC7oECoFYjZcH55qlIItByS0ULOO7dgrSa6eaVvGp1bhGclONRU8CX3ZwVLMG86G5GjApRjbh_jo2vAdGRIdiKZSwlw$ I have a few more questions I am hoping you can help me out with.

I am in the 'NH Changes 00-10' and the following code is not working: Median Home Values

renderPlot({

split the selected variable into deciles

get_data <- reactive({ sd.sf <- sd.sf %>% mutate( q = ntile( get(input$home.value), 10 ) ) })

ggplot( get_data() ) + geom_sf( aes( fill = q ), color=NA ) + coord_sf( datum=NA ) + labs( title = paste0( "Choropleth of Select Demographics: ", toupper(input$demographics) ), caption = "Source: Harmonized Census Files", fill = "Population Deciles" ) + scale_fill_gradientn( colours=rev(ocean.balance(10)), guide = "colourbar" ) + xlim( xmin = -13152029, xmax = -12931890 ) + ylim( ymin = 3812996, ymax = 3932084 )

})

I suspect is it the object 'home.value'. When I tried 'get(input$demographics' it worked. I am wondering if my dorling is not correct?

I am having a similar problem with 'Drivers of Change' it is telling me 'object 'mhmval12' not found'. If i was to put in another object, such as 'PNHWHT12' it worked. This is why I think it might be something with my dorling file.

Thank you in advance.

— Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/DS4PS/cpp-529-spr-2021/issues/33*issuecomment-2065494816__;Iw!!IKRxdwAv5BmarQ!fjLDC7oECoFYjZcH55qlIItByS0ULOO7dgrSa6eaVvGp1bhGclONRU8CX3ZwVLMG86G5GjApRjbh_jo2vAdGRIcbGI2sMA$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AMK2Y73Z5FBUXDRUJJWSLL3Y6BLGTAVCNFSM6AAAAABGMMUXHCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRVGQ4TIOBRGY__;!!IKRxdwAv5BmarQ!fjLDC7oECoFYjZcH55qlIItByS0ULOO7dgrSa6eaVvGp1bhGclONRU8CX3ZwVLMG86G5GjApRjbh_jo2vAdGRIdB4XC_8A$ . You are receiving this because you were mentioned.Message ID: @.***>

isaeusebio commented 7 months ago

Hi @voznyuky @AntJam-Howell !

Were you able to figure out what was wrong with your dorling/code? I am having a similar error pop up on my :

Input:

button.labels <- c("Median Home Value 2000","Median Home Value 2010","Value Change 2000-2010","Growth in Home Value")
button.values <- c("mhv.2000","mhv.2010","mhv.change","mhv.growth")

radioButtons( inputId="home.value", 
              label = h3("Home Values"),
              # choices = these.variables, 
              choiceNames=button.labels,
              choiceValues=button.values,
              selected="mhv.2000")

Row:

renderPlot({

# split the selected variable into deciles 

get_data <- 
  reactive({
             d <- 
             d %>% 
             mutate( q = ntile( get(input$home.value), 10 ) )  
          })

ggplot( get_data() ) +
    geom_sf( aes( fill = q ), color=NA ) +
    coord_sf( datum=NA ) +
    labs( title = paste0( "Spatial Distribution of Home Values: ", toupper(input$demographics) ),
          caption = "Source: Harmonized Census Files",
          fill = "Home Value Deciles" ) +
    scale_fill_gradientn( colours=rev(ocean.balance(10)), guide = "colourbar" ) + 
   xlim(xmin =  -13070000, xmax = -12975000 ) + 
    ylim( ymax = 3811250, ymin = 3910000 )

})

The error I get shows: Warning: Error in mutate: ℹ In argument: q = ntile(get(input$home.value), 10). Caused by error in get(): ! object 'mhv.2000' not found

AntJam-Howell commented 7 months ago

Hi please email me the rmd file you are working on to build the dorling.

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

On Sun, Apr 28, 2024 at 7:23 PM isaeusebio @.***> wrote:

Hi @voznyuky https://urldefense.com/v3/__https://github.com/voznyuky__;!!IKRxdwAv5BmarQ!d_c_KjbNE6Juy3u8NZ0SGB0MLU-bbZwIZuMvYUVWwDKjdAzoc6lg1K1wzVH6TgdxF1KW11qyMLOfynH8DYythCx2qOrrNQ$ @AntJam-Howell https://urldefense.com/v3/__https://github.com/AntJam-Howell__;!!IKRxdwAv5BmarQ!d_c_KjbNE6Juy3u8NZ0SGB0MLU-bbZwIZuMvYUVWwDKjdAzoc6lg1K1wzVH6TgdxF1KW11qyMLOfynH8DYythCzbBGLwnw$ !

Were you able to figure out what was wrong with your dorling/code? I am having a similar error pop up on my :

Input: ` button.labels <- c("Median Home Value 2000","Median Home Value 2010","Value Change 2000-2010","Growth in Home Value") button.values <- c("mhv.2000","mhv.2010","mhv.change","mhv.growth")

radioButtons( inputId="home.value", label = h3("Home Values"),

choices = these.variables,

choiceNames=button.labels, choiceValues=button.values, selected="mhv.2000")`

Row: `renderPlot({ split the selected variable into deciles

get_data <- reactive({ d <- d %>% mutate( q = ntile( get(input$home.value), 10 ) ) })

ggplot( get_data() ) + geom_sf( aes( fill = q ), color=NA ) + coord_sf( datum=NA ) + labs( title = paste0( "Spatial Distribution of Home Values: ", toupper(input$demographics) ), caption = "Source: Harmonized Census Files", fill = "Home Value Deciles" ) + scale_fill_gradientn( colours=rev(ocean.balance(10)), guide = "colourbar" ) + xlim(xmin = -13070000, xmax = -12975000 ) + ylim( ymax = 3811250, ymin = 3910000 )

})`

— Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/DS4PS/cpp-529-spr-2021/issues/33*issuecomment-2081788271__;Iw!!IKRxdwAv5BmarQ!d_c_KjbNE6Juy3u8NZ0SGB0MLU-bbZwIZuMvYUVWwDKjdAzoc6lg1K1wzVH6TgdxF1KW11qyMLOfynH8DYythCw8PLzMEw$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AMK2Y74ODDNHAZEXABTQOG3Y7WVLLAVCNFSM6AAAAABGMMUXHCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBRG44DQMRXGE__;!!IKRxdwAv5BmarQ!d_c_KjbNE6Juy3u8NZ0SGB0MLU-bbZwIZuMvYUVWwDKjdAzoc6lg1K1wzVH6TgdxF1KW11qyMLOfynH8DYythCwT9uSH4Q$ . You are receiving this because you were mentioned.Message ID: @.***>