Choropleth Maps in ggplot2
How to make Choropleth Maps in ggplot2 with Plotly.
Plotly Studio: Transform any dataset into an interactive data application in minutes with AI. Try Plotly Studio now.
Note: We are retiring documentation for R, MATLAB, Julia, and F#. Learn more about this change here.
County-Level Boundaries
library(plotly)
library(maps)
county_df <- map_data("county")
state_df <- map_data("state")
# create state boundaries
p <- ggplot(county_df, aes(long, lat, group = group)) +
geom_polygon(colour = alpha("black", 1/2), fill = NA) +
geom_polygon(data = state_df, colour = "black", fill = NA) +
theme_void()
fig <- ggplotly(p)
fig