Watts-College / cpp-529-spr-2022

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

NH Change Error #31

Open asukajames opened 2 years ago

asukajames commented 2 years ago

I changed the values but I am still getting an error.

Inputs {.sidebar}


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

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

Median Home Values


renderPlot({

# split the selected variable into deciles 

get_data <- 
  reactive({
             DC.sf <- 
             DC.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( "Spatial Distribution of Home Values: ", toupper(input$home.value) ),
          caption = "Source: Harmonized Census Files",
          fill = "Home Value Deciles" ) +
    scale_fill_gradientn( colours=rev(ocean.balance(10)), guide = "colourbar" ) + 
      xlim( xmin = -8800000, xmax = -8500000 ) + 
    ylim( ymin = 4600000, ymax = 4800000 )

})

Variable Distribution

renderPlot({

# extract vector x from the data frame 
# x <-  d[ "pnhwht12" ] %>% unlist()

get_variable_x <- reactive({ d[ input$home.value ] })

x <- get_variable_x() %>% unlist() %>% as.numeric()

cut.points <- quantile( x, seq( 0, 1, 0.1 ) )

hist( x, breaks=50, 
      col="gray", border="white", yaxt="n",
      main=paste0( "Histogram of ", toupper( input$home.value ) ),
      xlab="red lines represent decile cut points" )

abline( v=cut.points, col="darkred", lty=3, lwd=2 )

})

Error Problem with mutate() column q. i q = ntile(get(input$home.value), 10). x object 'mhv.growth' not found

Anybody getting the same problem??

jalehend commented 2 years ago

I'm having the same issue. I'm pretty sure the .geojson file is not capturing the data collected from lab 5, which is why "mhv.growth", or any of the DV's are not being found. I think if you just manually add the data from lab 5, including the three URLs, it will temporarily fix it. But I'm sure there is a better solution.

JasonSills commented 2 years ago

@jalehend, yes, this is great deduction! But your solution isn't optimal. I'm working with @asukajames via email. Perhaps @asukajames can offer some insights when it is working.

JPRayes commented 2 years ago

I'm having the same issue even though I changed all the values.

JasonSills commented 2 years ago

@JPRayes,

In both cases it ended up being issues with building the dorling cartogram dataset. If you haven't done so I recommend watching the last three lab sessions, particularly the third one back, and watch how it was built. You can also reach out to me via email if you remain stuck.

asukajames commented 2 years ago

@jalehend @JPRayes Sorry for my late response! I was having a hard time making the code work in the dashboard! My problem was the dataset. The merging order was wrong, therefore, mhv.00.x stayed in my dataset and kept messing up my dashboard.

JPRayes commented 2 years ago

What order are you referring to? The more I try to adjust my cartogram, the more errors I end up getting...

JPRayes commented 2 years ago

@asukajames can you elaborate on the merging order? I feel like I'm close, but I've been messing with my cartogram for so many hours now, I think I'm at the point of diminished returns.

dholford commented 2 years ago

@ JPRayes When you get to this step:

phx <- merge( phx, d, by.x="GEOID", by.y="tractid", all.x=T )

try:

phx <- merge(phx, d)

This will remove duplicates which may be your issue. You then have to do the extra step of making sure everything is there, but that may work. You could also try phx <- merge(phx, d, all.x = T)

JPRayes commented 2 years ago

So I was able to work through several issues and now have an almost fully functional dashboard: