-1

I have a dataset of all powerplants and I've got their locations down to the format the maps package in R likes c("arkansas,clay", "arkansas,conway", ...).

Some counties have more than one powerplant, and there are 7+ types of powerplants, so I'd like to plot them as points on a map and not just color the counties, as I can see the maps package mainly doing. Was thinking to jitter their position a bit. But I don't know how to go from state/county name to location, or plot straight up points in the maps package.

Does anyone have any suggestions?

Lucas Spangher
  • 339
  • 2
  • 14

1 Answers1

-1

So I couldn't figure out how to do it with the maps package, but with ggplot, it's almost trivial. The first few lines of this answer made it really easy to construct a plot I needed.

Plotting bar charts on map using ggplot2?

One trick I did use was to create R's version of a hastable from the map_data in ggplot2.

usaMap=maps_data("county")
usaMap$locCode=paste(usaMap$region,",",usaMap$subregion,sep="")

usaMap2 = usaMap[!duplicated(usaMap$locCode),]
row.names(usaMap2)=usaMap2$locCode
currentGen$long = usaMap2[currentGen$locCode,"long"]+rnorm(nrow(currentGen),0,.05)
currentGen$lat = usaMap2[currentGen$locCode,"lat"]+rnorm(nrow(currentGen),0,.05)

where currentGen is my powerplants data frame and the format of the region matches exactly the format of usaMap$locCode.

Community
  • 1
  • 1
Lucas Spangher
  • 339
  • 2
  • 14