Laden...
Map in R
Maps and other GIS operations can be processed very nicely in R as well! However, some additional packages are necessary. In this example, we load the packages sp
and raster
which are available on the CRAN server.
Moreover, a distinct shapefile of the respective region might be required. Some of those can be downloaded from the internet. For this example, I extracted the respective countries from a World-Shapefile. You can downloald it here.
This graphic was created using the following code:
library(sp)
library(raster)
shCA <- shapefile("CA.shp")
shCA <- spTransform(shCA, CRS('+proj = longlat +datum = WGS84'))
pop <- cut(shM$POPULATION, c(1,50000,1000000,10000000,50000000,100000000,150000000),levels = 1:7)
op <- par(mar = c(0.5, 0.5, 0.5, 0.5))
plot(1, 1, xlim = c(-120, -75), ylim = c(0, 40), axes = FALSE, xlab = "", ylab = "")
x1 <- seq(-125, -72, len = 200)
for(i in 1:200){
polygon(c(x1[i], x1[i] + 0.5, x1[i] + 0.5, x1[i]), c(-10, -10, 50, 50), col = colorRampPalette(c("#3d55af", "#27a7be"))(200)[i], border = NA)
}
for(i in seq(-115, -75, 10)) abline(v = i)
for(i in seq(5, 35, 10)) abline(h = i)
for(i in seq(-115, -85, 10)) text(i + 0.5, 40, paste(i, "° E"), adj = 0, cex = 0.7)
for(i in seq(5, 35, 10)) text(-120, i + 0.8, paste(i, "° N"), cex = 0.7)
plot(shM, col = terrain.colors(9)[shM$CODE], add = TRUE)
points(coordinates(shM), pch = 21,bg = adjustcolor(2, 0.6), cex = c(0.7, 1, 1.3, 1.6, 1.9, 2.2, 2.5)[bv])
legend(-114.5, 7, legend = c("<50,000", "50,001-1,000,000", "1,000,001-10,000,000", "10,000,000-50,000,000", "50,000,000-100,000,000", ">100,000,000"), pch = 21,
pt.bg = adjustcolor(2, 0.6), pt.cex = c(0.7, 1, 1.3, 1.6, 1.9, 2.2, 2.5), box.col = "white", ncol = 2, cex = 0.8, title = "Population", bg = "white")
arrows(-82, 28, -82, 32, lwd = 2.5, length = 0.15)
text(-82, 34, "N", cex = 1.5)
par(op)
Map, different colours, transparency, background colour, dependent size, dependent colours, box, x-axis, y-axis, bottom, left, top, right, labels, without ggplot, legend, coordinate system, Longitude, Latitude, Central America, Mexico, Guatemala, Belize, Nicaragua, Honduras, El Salvador, Panama