Illya Illya - 1 year ago 96
R Question

R choropleth map of the Dominican Republic

I would like to make a choropleth map of the Dominican Republic. As for boundaries, all I need are the states within that country.

I have tried the following:

map <- GetMap('Dominican Republic' , zoom = 8 , )
PlotPolysOnStaticMap(map , polys)

Answer Source

You can do this without RGoogleMaps. There are shapefiles & RData files at UC Davis for every region on the planet. The following annotated code:

  • downloads an RData SpatialPolygonsDataFrame of the admin level 1 areas of DR
  • grabs my theme_map
  • makes a sample data set
  • plots a choropleth with a proper map projection for the DR

You can use other actual shapefiles in similar fashion:


# theme_map

# the DR "shapefile"
download.file("", "DOM_adm1.RData")

# for plotting with ggplot2
dr_map <- fortify(gadm)

# build some sample data, note that we'll be using
# the polygon "id" for plotting so you'll need that in the
# data frame
choro <- data.frame(id=gadm@data$ID_1,
                    value=sample(100, nrow(gadm@data)))

# you can look at the data with this (it won't be shown here)

# plot
gg <- ggplot()

# base map layer
gg <- gg + geom_map(data=dr_map, map=dr_map,
                    aes(x=long, y=lat, map_id=id),
                    fill="white", color="#7f7f7f", size=0.25)

# DR choro layer
gg <- gg + geom_map(data=choro, map=dr_map, 
                    aes(fill=value, map_id=id), 
                    color="#7f7f7f", size=0.25)

# lambert is a gd proj for DR
gg <- gg + coord_map("lambert", lat0=17.5, lat1=20)

# clean up map chart junk
gg <- gg + theme_map()

# move legend
gg <- gg + theme(legend.position="right")

# plot it

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download