[R] Colorramp in Maptools, how to choose min and max values for the fg= argument

Jannis bt_jannis at yahoo.de
Tue Sep 21 20:11:16 CEST 2010


Hi Katrin,


your problem is not related to maptools, rather to the base function "colorRampPalette". In my opinion the easiest way to get what you want is to use colorRamp:

Vector=c(2,3,4,5,6)
color.ramp <- colorRamp(c('white','black'))
map.colors <- color.ramp(Vector/10)

The 10 refers to the maximum value that you specified. You just have to adjust the colors.


HTH
Jannis


--- schaber <kschaber at ipp.mpg.de> schrieb am Di, 21.9.2010:

> Von: schaber <kschaber at ipp.mpg.de>
> Betreff: [R] Colorramp in Maptools, how to choose min and max values for the fg= argument
> An: r-help at r-project.org
> Datum: Dienstag, 21. September, 2010 15:42 Uhr
> 
> Hello,
> 
> I am using maptools for plooting geographical data.
> The colour of the region indicates some region dependent
> value (population for example).
> 
> I pass the colours of the regions to the plot.Map function
> by defining the foreground colour:
> 
> jet.colors = colorRampPalette(c("#00007F", "blue",
> "#007FFF",  "cyan", "#7FFF7F", "yellow", "#FF7F00",
> "red", "#7F0000"))
> n=100
> cols <- jet.colors(n)
> Intervalls =  cut(as.numeric(Vector),n, na.rm=TRUE)
> fgs <-cols[Intervalls] ## is there some
> option/possibility here to choose colours differently ??
> plot.Map(Shape.map, fg=fgs, ol=NA, bty="n", xlab="",
> ylab="", xaxt="n", yaxt="n")
> 
> My problem is the following: I would like to choose minimal
> and maximal value of the colour palette, different from the
> minimal and maximal values of the Vector. For example:
> Vector=c(2,3,4,5,6), but the maximal colour should
> correspond to 10 and the minimal to 0.
> 
> I know, that maptools is not the most actual solution to
> plot maps, but I am building on an old code and therefore do
> not want to change it.
> 
> I would very much appreciate any help or hints!!
> Katrin
> 
> 
> -----Integrierter Anhang folgt-----
> 
> ______________________________________________
> R-help at r-project.org
> 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.
> 





More information about the R-help mailing list