Generate ggplot2
geom_map
Mexico county maps
This is a simple package with one purpose:
For installation, do:
library(devtools)
# Download Library (read Notes)
install_github("nicholasbucher/ggcountymx")
library(ggcountymx)
# Load dataset to Enviroment (read Notes)
data(geomx)
BCS <- ggcountymx("03") # Entity code as Character
BCS$gg
To get:
The BCS
object in the above code contains
gg
ggplot2 objectmap
object which is the polygon points data framemun.names
object which is a list of all municipality names with FIPS codes in that municipalitygeom
object (geom
) for the municipality mapThis lets you add further map layers (e.g. for a choropleth):
# built-in MEX socioeconomic by FIPS code data set from ENIGH 2016
data(socioeconomic)
# define appropriate (& nicely labeled) socioeconomic breaks
socioeconomic$brk<-cut(socioeconomic$Level,
breaks=c(0, 0.5 , 1 , 1.5 , 2 , 2.5 , 3 ,3.5 , 4),
labels=c("Outcast",
"Low",
"Lower Middle",
"Middle",
"Upper Middle",
"Lower High",
"Middle High",
"Upper High"),
include.lowest=TRUE)
# get the Mexico municipality map
BCS <- ggcountymx("03")
# start the plot with our base map
gg <- BCS$gg
# add a new geom with our population (choropleth)
choro_geom <- geom_map(data=socioeconomic,
map=BCS$map,
aes(map_id=FIPS, fill=brk),
color="white", size=0.125)
gg<-gg + choro_geom
# define nice colors
choro_color<-scale_fill_manual(values=c("#ff0000", "#ff4000", "#ff8000",
"#ffbf00", "#ffff00", "#bfff00",
"#80ff00","#40ff00"),
name="Socioeconomic Class")
gg<-gg + choro_color
# plot the map
gg
And, combining individual maps is pretty straightforward:
BCN <- ggcountymx("02", fill="#c7e9b4", color="white")
BCS <- ggcountymx("03", fill="#41b6c4", color="white")
SON <- ggcountymx("26", fill="#253494", color="white")
BCS$gg + BCN$geom + SON$geom
data(geomx)
.resolution
parameter reduces the percetage of points used.Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.