[R] wrong fill colors in polygon-map
Roger Bivand
Roger.Bivand at nhh.no
Tue Nov 7 13:27:10 CET 2006
On Tue, 7 Nov 2006, Frosch, Katharina wrote:
> Dear all,
>
> I would like to produce a map with information about the patenting
> activity in German districts, by coloring districts with different
> degrees of patenting activity in different colors. I work with the
> packages maptools, maps and spdep. The map data is read from an external
> .shp file (+ the corresponding .shx and .dbf files). Plotting a map with
> the IDs or the patenting indicator itself works fine. But coloring the
> map leads to completely odd results (wrong colors for most of the
> regions). I also tried simpler values (just 0 and 1 for different
> regions), same problem. I tried to check whether there is any problem
> with the match of data and district ids, but everything seemed to be
> fine.
>
> Sample code:
> ****************
> brks.pat<-quantile(patenting$patbus)
> #palette.pat<-c("green", "blue", "grey", "darkgrey", "red")
> palette.pat<-c(rep("green", 4), "red")
> plot(iab7.poly, col=palette.pat[findInterval(patenting$patbus,
> brks.pat)])
> legend(1200, -200, fill=palette.pat, legend=round(brks.pat,2), cex=0.6)
> title(main="patenting activity in german districts")
>
> Data:
> ******
> Iab7.poly contains the polygons of 343 German districts
> patenting$patbus contains the number of corporate patents per 100.000
> inhabitants for each district
(R-sig-geo may be a more focussed list for this kind of question)
If the polygons in Iab7.poly are in the same order as the rows of
patenting, and the number of polygons is the same as the number of rows,
it is possible that the breakpoints are not quite what you think (if for
example some of the quantiles are equal, which happens with zero-inflated
data). Omitting all.inside=TRUE in findInterval() can also lead to the
insertion of NA values into the vector of colours.
Perhaps have a look at the classInt package for some examples of choosing
class intervals i.a. for map display.
Roger
>
> Any ideas would be appreciated!
>
> Best regards,
> Katharina
>
>
>
> ******************************
>
> Katharina Frosch
> Rostock Center for the Study of Demographic Change
> Konrad-Zuse-Str. 1
> 18057 Rostock
> Tel.: (0381) 2081-148
> Fax: (0381) 2081-448
> Mail: frosch at rostockerzentrum.de
>
>
>
>
>
>
> ----------
> This mail has been sent through the MPI for Demographic Rese...{{dropped}}
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-help
mailing list