Open Treetopflier opened 5 years ago
This map?
object 'White' not found
would suggest that you either need to reference a dataset so ggplot() knows where to look for the variable "white", or that you need to enclose an argument with quotes so that it is not looking for an object called white.
Do either of those work?
I need these files to replicate:
# Write into new csv file
write.csv( race.pop, "/home/anthony/Documents/Capstone/Race/race_pop.csv", row.names=T)
# Import Shapefile
county_shp <- "/home/anthony/Documents/Capstone/2010/tl_2010_04013_tract00.shp"
Yeah, I understand the error. I only included that one because the path should be fine. I've had a large range of other errors as well. shapefiles and racepop.zip
also if you notice in my code, I'm not mutating a categorical variable like in the example. So even if it worked, it'd only be one map. I was just trying to get something to work. I've also tried referencing lists with the var names, made new variables with the others in them like in the example.. changed nearly every other variable I have to make it like in the example, and finding other examples that provide similar results all to the same effect.
The following link provides an example creating split maps that I can't seem to replicate. https://andrewbtran.github.io/NICAR/2019/mapping/01_maps_code.html (Search Keywords: Transforming and mapping the data )
The data in the example does not pull like mine. they have a separate vector titled 'variable' which acts as a categorical variable defining race, and a separate vector called estimate. In contrast, my data does not have duplicate rows for census tracts to define race-- I have one row with the tract, the 5 race variables, a variable containing the total of the previous five, and five separate race variables that I created that takes the raw count divided by the total * 100 to get the percentage. This is problematic, because I can't for the life of me figure out how to create split maps like the example below when they facet wrap a categorical variable I do not have.
I've also tried about 50 other variations. Different errors, same result. Replicating Race.txt
mcpa %>% mutate(pct = 100 * (White / Total)) %>% ggplot(aes(fill = pct, color = pct)) + facet_wrap( c(White, Black, American_Indian_Eskimo_or_Aleu, Asian_or_Pacific_Islander, Other_Race )) + geom_sf() + scale_fill_viridis(direction=-1) + scale_color_viridis(direction=-1) + theme_void() + theme(panel.grid.major = element_line(colour = 'transparent')) + labs(title="Racial geography of Maricopa County", caption="Source: US Census 2010")
Error in inherits(x, "mapping") : object 'White' not found