Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I plot a continents map with R?

Tags:

plot

r

maps

There are many solutions to plot maps at country level, but in my case I want to print statistics at continent level.

The only thing that comes into my mind is to use the country level maps and use a list of countries for each continent, but I was wondering if there is any simple solution for this kind of maps. To implement my idea it would be like this:

## produce the world map
map()
## list of countries per continent
SA <- c("argentina", "bolivia", "brazil", "chile", "colombia", "ecuador", "guyana", "paraguay", "peru", "suriname", "uruguay", "venezuela")
map(regions = SA, fill=TRUE, add=TRUE)

worldmap

like image 577
David Ameller Avatar asked Nov 22 '13 14:11

David Ameller


People also ask

How do I plot a world map in R?

To create a world map using it we will use the geom_map() function of the ggplot2 package of the R Language. This function returns a ggplot object so all the functions that work on other ggplot plots will be working in geom_map() too. where, data: determines the data be displayed in this layer.


1 Answers

library(sp) #Load your libraries
library(maptools)
#Download the continents shapefile
download.file("http://baruch.cuny.edu/geoportal/data/esri/world/continent.zip",
              "cont.zip")
#Unzip it
unzip("cont.zip")
#Load it
cont <- readShapeSpatial("continent.shp")
#Plot it
plot(cont,
     col=c("white","black","grey50","red","blue","orange","green","yellow")) 
#Or any other combination of 8 colors

enter image description here

like image 127
plannapus Avatar answered Sep 27 '22 15:09

plannapus