The Maps library allows to quickly display most common maps: world and USA for example. It avoids to get the shapefile of these regions from the web. Its utilization is straightforward. Here are a few examples.
1 2 3 4 |
# load library library(maps) # draw a worldmap map('world',col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05, mar=rep(0,4),border=0, ylim=c(-80,80) ) |
Once you have these background, you can draw on it with usual plotting functions. Let’s add points and text:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# Create data data=as.data.frame(rbind( Buenos_aires=c(-58,-34), Paris=c(2,49), Melbourne=c(145,-38), Saint.Petersburg=c(30.32, 59.93), Abidjan=c(-4.03, 5.33), Montreal=c(-73.57, 45.52), Nairobi=c(36.82, -1.29), Salvador=c(-38.5, -12.97) )) colnames(data)=c("long","lat") # make the map map('world',col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,mar=rep(0,4),border=0, ylim=c(-80,80) ) points(x=data$long, y=data$lat, col="slateblue", cex=2, pch=20) text(rownames(data), x=data$long, y=data$lat, col="slateblue", cex=1, pos=4) |
Note that several places are available in the memory of this library:
1 2 3 4 |
map('county', col="#f2f2f2", fill=TRUE, bg="#A6CAE0", mar=rep(0,4), border=0) map('france',col="#f2f2f2", fill=TRUE, bg="#A6CAE0", mar=rep(0,4), border=0 ) map('nz',col="#f2f2f2", fill=TRUE, bg="#A6CAE0", mar=rep(0,4), border=0 ) map('italy', fill=TRUE, col="#f2f2f2", bg="#A6CAE0", mar=rep(0,4), border=0 ) |
Not what you are looking for ? Make a new search ![mediatagger]
Leave a Reply