[R] color.ramp in maptools
Roger Bivand
Roger.Bivand at nhh.no
Fri Mar 26 20:16:02 CET 2004
On Fri, 26 Mar 2004, Marco Albani wrote:
> Roger Bivand wrote:
> > On Fri, 26 Mar 2004, Marco Albani wrote:
> > At
> >>the moment I have some trouble understanding how the " auxvar " variable
> >>is supposed to be used in the plot.Map function.
> >>
> [...]
> >>
> >>I don't seem to be able to get any information on this color.ramp
> >>function. In fact the function doesn't seem to exist if I search for it
> >>with ls()
> >>
> >>Does anyone have any insight?
> >
> >
> > The function is not exported in the package namespace (you can read it
> > using the ::: operator: maptools:::color.ramp will display it). Its usage
> > is: color.ramp(nclass,color='red',nvec=NULL,type='q'), where: nclass is
> > the number of classes desired in the ramp; color is the base color to
> > build the ramp on; nvec is the numeric vector (or factor) from which to
> > build the ramp; and type is the type of binning procedure to use (default
> > quantiles, if set to "e", it will use equal-sized bins.).
> >
>
> Thank you. So the way I understand it is that auxvar will actually be
> passed as nvec to color.ramp
>
> I tried passing a numeric vector with the following summary stats:
>
> summary(NE.HWA.pols$att.data$RockDepth)
> Min. 1st Qu. Median Mean 3rd Qu. Max.
> 0.0 100.0 120.0 112.7 140.0 160.0
>
> And on call
>
> plot.Map(NE.HWA.pols, auxvar = NE.HWA.pols$att.data$RockDepth)
>
> I got this error
>
> Error in cut.default(nvec, brks, labels = FALSE, include.lowest = TRUE) :
> cut: breaks are not unique
>
Well, I did say the code isn't often used (AFAIK), and that cut() can bite
- as its name suggests. One possibility is to try a different nclass=, but
I think the code of maptools:::color.ramp needs to be modified (in two
places) to remove duplicate breaks. Put a brks <- unique(brks) before the
two calls to cut(), if you like (done in release to come when 1.9.0 is
out - thanks for drawing attention to the problem).
Otherwise follow other users' experience, and define your class intervals
before calling plot.Map(). Automating class intervals for choropleth maps
is not easy, and there are very many alternative maps that can be created
for even small n polygons and k classes.
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no
More information about the R-help
mailing list