For my school assignment, I am trying to make a map of the Netherlands filled with a color scheme, which depends on integer numbers (number of citizens). I have a dataset called mun_neth, which is a SpatialPolygonDataFrame and contains all the polygons of the Netherlands and all the data I want to build. I tried three different methods that I added under it. I also put error messages at the bottom. I think I misunderstand the fill requirement. Where does this go wrong and how do I fix it?
After searching here on stackoverflow, I feel like I'm pretty close to building a map. But, unfortunately, it does not work yet.
getwd()
setwd("~/Wageningen/2.2 Geoscripting/data")
install.packages("RCurl", dependencies=TRUE)
library(RCurl)
install.packages("ggplot2", dependencies=TRUE)
library(ggplot2)
install.packages("rgdal", dependencies=TRUE)
library(rgdal)
dl_from_dropbox <- function(x, key) {
require(RCurl)
bin <- getBinaryURL(paste0("https://dl.dropboxusercontent.com/s/", key, "/", x),
ssl.verifypeer = FALSE)
con <- file(x, open = "wb")
writeBin(bin, con)
close(con)
message(noquote(paste(x, "read into", getwd())))
}
dl_from_dropbox("Netherlands.zip", "bocfjn1l2yhxzxe")
unzip("Netherlands.zip")
mun_neth <- readOGR('gem_2012_v1.shp', layer = 'gem_2012_v1')
mun_neth <- readOGR('gem_2012_v1.shp', layer = 'gem_2012_v1')
mun_neth@data$id <- rownames( mun_neth@data )
mun_neth.df <- as.data.frame( mun_neth )
mun_neth.fort <- fortify( mun_neth , region = "id" )
mun_neth.gg <- join( mun_neth.fort , mun_neth.df , by = "id" )
ggplot(data = mun_neth, aes(long, lat, group=group)) +
geom_map(aes(fill = mun_neth$AANT_INW, color = category), map =mun_neth.gg) +
scale_fill_gradient(high = "red", low = "white", guide = "colorbar")
scale_colour_hue(h = c(120, 240))
Regions defined for each polygon
Error: cannot allocate 9.5 MB vector
ggplot(mun_neth$AANT_INW, aes(x=T_MEAN))
: ggplot2 , integer
ggplot(aes(x=x,y=y,fill=AANT_INW),data=mun_neth)
,
: