[R-sig-Geo] Problem with China GADM map data?

Oscar Perpiñan oscar.perpinan at upm.es
Fri Feb 7 12:58:55 CET 2014


Hello,

I have cleaned some parts of your code. It runs ok in my computer. The
error message you get is related to the conversion of non-ascii
characters. What is the result of sessionInfo() in your computer?

Best,

Oscar.

library(sp)
library(raster)
library(RColorBrewer)

chn1 <- getData('GADM', country="CHN", level=1)

# Creating my (artificial) groupings of Chinese admin units:
nrofunits <- length(chn1$NAME_1)

groups <- c(rep(1:3,(nrofunits%/%3)),rep(1,2))[order(c(rep(1:3,(nrofunits
%/% 3)),rep(1,2)))]

chn1$groups <- as.factor(groups)


mypalette <- brewer.pal(3,"Reds")
spplot(chn1, zcol="groups", col.regions=mypalette,
       colorkey=FALSE,
       par.settings=list(axis.line=list(col='transparent')))
-----------------------------------------------------------------
Oscar Perpiñán Lamigueiro
Dpto. Ingeniería Eléctrica (ETSIDI-UPM)
Grupo de Sistemas Fotovoltaicos (IES-UPM)
URL: http://oscarperpinan.github.io
Twitter: @oscarperpinan


2014-02-07 Miriam Lo <lazyhydra at gmail.com>:
> Dear all
>
> I've recently tried coloring different provinces in different colours for a
> given country.  While I could do this on countries like US and UK, I came
> across a problem when colouring China.  Would anybody know what's wrong
> with the code/ any ways to get around the issue? Does this have anything to
> do with Chinese language support in R? Many thanks.
>
> Regards
> Miriam
>
> *Code:*
>
> library(raster)
> library(RColorBrewer)
> library(ggplot2)
>
> # Getting the data:
>
> chn1<-getData('GADM', country="CHN", level=1)
> class(chn1)
>
> # Creating my (artificial) groupings of Chinese admin units:
> nrofunits<-length(chn1$NAME_1)
> print(chn1$NAME_1)
> groups<-c(rep(1:3,(nrofunits %/%3)),rep(1,2))[order(c(rep(1:3,(nrofunits
> %/% 3)),rep(1,2)))]
>
> # adding values (grouping values) to "data" and calling this new variables
> "groups"
> chn1 at data["groups"]<-groups
> chn1 at data$groups<-as.factor(chn1 at data$groups)
>
> mypalette<-brewer.pal(3,"Reds")
> spplot(chn1,zcol="groups",col.regions=mypalette,colorkey
> =FALSE,par.settings=list(axis.line=list(col='transparent')))
>
>
> *Error:*
>
> Error in sort.list(y) :
>   invalid input '檨ᙞศে㶘綤￿ÿ  ǫ̌桤汔 ' in 'utf8towcs'
>
>         [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list