VIS-2129-F2020 / jiwonpark-vis

0 stars 0 forks source link

Question for VIS assignment-2 #2

Closed jiwonpark1994 closed 4 years ago

jiwonpark1994 commented 4 years ago

Hello Carole, Alex, and Taelor!

While I was working on the second VIS assignment, I had a question about integrating the state names on the map. Below are the links to the relevant files I've pushed. https://vis-2129-f2020.github.io/jiwonpark-vis/Assignment-2.Rmd https://vis-2129-f2020.github.io/jiwonpark-vis/Assignment-2.html

So my question is : How can I add the abbreviation of the name of the states to the "choropleth map", and also to other maps in general? At first, I tried to follow the flows of the additional tutorial (https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-2.html), but I'm confused that how I might integrate the world data - as explained, which includes the name of the states by default - to the map I'm working on.

Could you please let me know how I might solve this? I assigned three of you at this time, but let me know I should assign less next time:)

Thanks! Jiwon

jiwonpark1994 commented 4 years ago

Can I add one more question? How can I add population data to the proportional symbol map (located in the last part) by filling colors? I tried the code I attached below and didn't work with an error message that "R doesn't recognize the object "long" and "lat". Below is my code!

geom_polygon(data=poverty_states, aes(x=long, y=lat, group=group, fill = tot_popE/1000000), color="black", size = 0.2) +

scale_fill_continuous(name="State Population", low = "lightblue", high = "darkblue",limits = c(0,40), breaks=c(5,10,15,20,25,30,35), na.value = "grey50") +

c-voulgaris commented 4 years ago

All line numbers refer to the current draft on GitHub.

On your first question: The state abbreviations are in a variable called "postal", so you'll need to add that to the list of variables you select in line 111. So line 111 becomes : select(name, tot_popE, rat_pov, med_incomeE, mon_housE, postal)

Then you need add variables for the x,y coordinates of the centroids by adding these lines somewhere before line 119:

poverty_states <- cbind(poverty_states, st_coordinates(st_centroid( poverty_states$geometry)))

Then, at line 125, add this to actually label the states: geom_text(aes(label = postal, x = X, y = Y), check_overlap = TRUE) +

By setting check_overlap = TRUE, you're telling R not to print overlapping labels, so small states on the East Coast might nor be labeled. If you want to make sure there's a label for every single state, then you can set that to FALSE, but you'll find that some of the labels are printed on top of each other.

For question 2, are you saying you want to sizes of the symbols to represent the percentage of the population below the poverty rate and the color to represent the population? That seems like an odd thing to do, but to do that, you would:

It seems more natural to represent population with size and poverty rate with color. If that's what you want to do, then just switch 'color' and 'size in the suggestion for line 156 above.

jiwonpark1994 commented 4 years ago

Thank you so much for your help! I followed your advice, and it was successful:)