[R] wrong fill colors in polygon-map
Roger Bivand
Roger.Bivand at nhh.no
Tue Nov 7 20:46:50 CET 2006
On Tue, 7 Nov 2006, Frosch, Katharina wrote:
> Dear Roger: Thank you for your help and the hint with the R-sig-geo list
> (next time I'll post directly to it)!
>
> I went again through all points you mentioned:
> - polygons and rows of data are in the same order
> - the number of polygons and data rows is identical
> - I experimented with different values, and also defined explicit
> breakpoints without using the quantile (no effect)
> - then I added all.inside=TRUE in findIntervall (no effect)
>
> However, adding the forcefill=FALSE option to the plot command led to a
> strange effect: three districts were left blank. Two of these districts
> were districts that are situated around another district (district
> A=city itself, district B=the countryside around). The third problematic
> district is situated close to the Swiss border and next to a big lake. I
> deleted the three districts, to see what happens. The problem is partly
> resolved, but new blank districts appear.
>
> Could this be caused by a corrupted shape file rathern than by R? I
> loaded the shape-file with the Program Mapviewer in MIF/MID format,
> unionized some districts, then exported it to an ESRI-shapefile and used
> it in R.
It is at least worth trying. May I suggest reading the MIF/MID file
directly into R using the readOGR() function in the rgdal package? If you
are a Mac OSX user, there is extra help needed installing rgdal, but on
Windows it is available for binary install directly from CRAN (thanks to
Uwe Ligges). The spatial classes used there are more robust, and the data
and polygons can be kept together. Polygons may also be dissolved using
objects of the SpatialPolygons class.
Could I suggest that you move any reply to R-sig-geo, given that the
details of spatial data formats are not of general interest?
Roger
>
> I don't have any clue to resolve this...so any hint is very welcome!
> Katharina
>
>
>
> **************************
> Katharina Frosch
> Rostocker Zentrum
> Konrad-Zuse-Str. 1
> 18057 Rostock
> Tel.: (0381) 2081-148
> Fax: (0381) 2081-448
> Mail: frosch at rostockerzentrum.de
>
>
>
>
> -----Original Message-----
> From: Roger Bivand [mailto:Roger.Bivand at nhh.no]
> Sent: Dienstag, 7. November 2006 13:27
> To: Frosch, Katharina
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] wrong fill colors in polygon-map
>
> 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