[R-sig-Geo] draw a map

Lyndon Estes lyndon.estes at gmail.com
Tue Nov 8 15:23:12 CET 2011


Hi Maria,

Please see my inserts below.

> ---
> The script is as following:
>
> install.packages("sp")
> library(sp)
>
> #load the map #
> mapchina<- url("http://www.gadm.org/data/rda/CHN_adm1.RData")
>
> load(mapchina)
> mapchina=gadm
>
> gadm$NAME_1   #shows the name of the Chinese regions
>
> #create the vector of data that we want to draw in the Chinese map,. Notice
> that follow the same order that NAME_1 #
>
> valor=c(99.09,70.62,0,49.13,42.13,40.53,46.10,40.36,0,71.87,38.71,
> 82.36,69.76,62.68,76.17,70.43,47.96,42.34,49.65,44.42,0,41.19,66.42,
> 61.04,76.75,82.75,44.69,75.37,20.53,21.25,38.10,89.74)
>
> var1<-data.frame(valor)
>
> # add the vector of data into the map

# There was no mapa object, so maybe you had it already created it, and
# forgot to include it
mapa <- mapchina

> mapa at data=data.frame(var1)
>
> #plot the map
> spplot(mapa,c("var1"))  # Wrong variable name

# You want this instead, since the column header for the dataframe you
# joined to maps is "valor", not "var1"
spplot(mapa,"valor")  # This plots for me


Cheers, Lyndon



More information about the R-sig-Geo mailing list