I would like to plot pie charts of different fuel type for each state on USA map. my data includes fuel types and their amount and each state id. I want to know how to plot pie on map for each state with state id?
Thanks,
data <- data.frame(region= c(AL, AR, AZ, CA, IA),
gas= c(25, 45, 45, 60, 75),
coal= c(45, 50, 45, 20, 15),
wind= c(30, 5, 10, 20, 10),
solar= c(10, 10, 10, 10, 10))
Update The
usmaphas been modernized in version0.7.0and now returns data as simple features. Hence, getting the coordinates for the scatter pies requires slightly more effort to retrieve the coordinates from the sf object:Original answer
Using the
usmapand thescatterpiepackages this could be achieved viaggplot2like so:usmapdata::centroid_labelsgeom_scatterpieEDIT If you want to exclude some states (or include only some states) you could do so via the
excludeorincludeargument ofplot_usmap:DATA