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
usmap
has been modernized in version0.7.0
and 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
usmap
and thescatterpie
packages this could be achieved viaggplot2
like so:usmapdata::centroid_labels
geom_scatterpie
EDIT If you want to exclude some states (or include only some states) you could do so via the
exclude
orinclude
argument ofplot_usmap
:DATA