I wonder whether I can color countries using ggplot
? Using rworldmap
this is pretty simple and adding points to lat/long values via ggplot
is easy as well.
Is there a way of coloring countries based on a simple table using ggplot
(country names in ISO3 and a number for each country?) The coloring should be based on the count.
p <- ggplot(legend=FALSE) +
geom_polygon(fill = "darkseagreen", data=world, aes(x=long, y=lat,group=group)) +
geom_path(colour = "grey40") +
theme(panel.background = element_rect(fill = "lightsteelblue2", colour = "grey")) +
theme(panel.grid.major = element_line(colour = "grey90")
) +
theme(panel.grid.minor = element_blank()) +
theme(axis.text.x = element_blank(),
axis.text.y = element_blank()) +
theme(axis.ticks = element_blank()) +
xlab("") + ylab("")
It's pretty straightforward with ggplot. In the following I use a GeoJSON version of the Natural Earth country boundaries (which stores the ISO3 code in
iso_a3
) projected to Winkel-Tripel. I stored a CSV of World Bank population data in a gist and read that in for the simple table. I then build two layers, one base layer for the world geometries then the filled-in polygons. Since it's pre-projected, I usecoord_equal
vscoord_map
(which is fine for choropleths but not so much if you intend to draw lines as you'll need to pre-project them, then, too):