2

I am trying to plot points on a US map in a density dot format where the dot for each zip code is sized based on how many people are a certain profession in that zip code. I have gotten very close to what I need, but am struggling to get the coordinates for Alaska and Hawaii where they need to be on an inset map. The first set of code here is what I have.

loc_full2 %>% filter(cns2!=0) %>% ggplot() + 
  geom_polygon(data=fifty_states, aes(x=long, y=lat, group = group),color="black", fill="white" ) + 
  geom_point(aes(x=lng, y=lat, size = cns2),alpha=.3,col="grey10") + 
  scale_size_continuous(range=c(1,10))+
 scale_size(name="", range = c(2, 10)) + 
  guides(size=guide_legend("# CNM")) +
  #theme_void()

I have seen in this post (Relocating Alaska and Hawaii on thematic map of the USA with ggplot2) W. Murphy has a simple answer to get the information in the right spot for a choropleth map, but unfortunately, I need to use zipcodes and dots instead of just coloring.

The files I am working with are not shape files, but rather simple csv files with the columns 'zip code', 'state', 'lat', 'long', and 'count' and then I was using the fifty_states function from the fiftystater package to create the map of the country.

The other thing is that I can't seem to correct the legend scale to be integers instead of having decimal places.

This is what I have:

Map without Alaska and Hawaii in correct positions

This is what I need: Map with Alaska and Hawaii in correct positions

Thank you for any help!

Mark
  • 7,785
  • 2
  • 14
  • 34
Sophia
  • 99
  • 5
  • 1
    For the legend, manually set your breakpoints and labels using `scale_size_manual()`. – M-- Aug 31 '23 at 21:05
  • Can you list all of the packages you used (ie where did "fifty_states" come from) and provide a sample data of the Alaska and Hawaiian zip codes? – Dave2e Aug 31 '23 at 21:49
  • 1
    Package {cowplot} makes plot insets a little easier. You could prepare three maps (main, Alaska and Hawai) and inset Alaska and Hawai with desired sizes (zooms) and positions. See: https://wilkelab.org/cowplot/articles/drawing_with_on_plots.html#making-inset-plots-1 – I_O Aug 31 '23 at 21:55
  • @Dave2e fifty_states is actually an R built in dataframe (https://rdrr.io/cran/fiftystater/man/fifty_states.html), and then i used ggplot2 and dplyr – Sophia Aug 31 '23 at 22:03
  • I can't seem to get cowplot to work since the geom_polygon for fifty_states is still not mapping the points on Alaska – Sophia Aug 31 '23 at 22:46

0 Answers0