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

Oscar Perpiñan oscar.perpinan at upm.es
Fri Feb 7 13:31:22 CET 2014


I think you have to change your locale configuration with
Sys.setlocale. For example, try Sys.setlocale('LC_ALL', 'C').
I have found a post in stackoverflow that describes a problem (with
solution) very similar to yours:
http://stackoverflow.com/questions/5031630/how-to-source-r-file-saved-using-utf-8-encoding
Best,

Oscar.
-----------------------------------------------------------------
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>:
> Hi Oscar
>
> Many thanks for your help! I've tried running the cleaned code but still
> couldn't get it to work.  The results of running sessionInfo() is as
> follows.  Is there anything that I could adjust the settings such that it
> converted the non-ASCII characters correctly?
>
> Regards
> Miriam
>
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United
> Kingdom.1252    LC_MONETARY=English_United Kingdom.1252
> [4] LC_NUMERIC=C                            LC_TIME=English_United
> Kingdom.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] raster_2.2-12      sp_1.0-14          RColorBrewer_1.0-5
> MASS_7.3-29        mapproj_1.2-2      maps_2.3-6
> [7] ggmap_2.3          ggplot2_0.9.3.1
>
> loaded via a namespace (and not attached):
>  [1] colorspace_1.2-4    dichromat_2.0-0     digest_0.6.4
> grid_3.0.2          gtable_0.1.2        labeling_0.2
>  [7] lattice_0.20-23     munsell_0.4.2       plyr_1.8
> png_0.1-7           proto_0.3-10        reshape2_1.2.2
> [13] RgoogleMaps_1.2.0.5 rjson_0.2.13        RJSONIO_1.0-3
> scales_0.2.3        stringr_0.6.2       tools_3.0.2
>
>>
>
>
> On Fri, Feb 7, 2014 at 11:58 AM, Oscar Perpiñan <oscar.perpinan at upm.es>wrote:
>
>> 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
>> >
>>
>
>         [[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