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

schaber kschaber at ipp.mpg.de
Wed Sep 22 10:56:51 CEST 2010


Hi Jannis,

thanks a lot for your reply. Unfortunately the solution you proposed 
does not work.
Maybe the reason is, that plot.Map only accepts hsv colours and I do not 
know to convert the rgb colours to the right colour space.

Isn't there a possibility to specify minimal an maximal values when 
using colorRampPalette to only choose a certain part of the 
colorRamp(Palette)? I could than define a new colorset  jet.colors2, 
which is picks out the colours between min(Vector)/10 and max(Vector)/10?

jet.colors = colorRampPalette(c("#00007F", "blue", "#007FFF",
                                 "cyan", "#7FFF7F", "yellow", "#FF7F00", 
"red", "#7F0000"))
Intervalls <- cut(as.numeric(Matrix[,nc]),n, na.rm=TRUE)  }
 fgs <- jet.colors(n)[Intervalls]

Maybe this is a bit confusing...

Thanks anyway for any help!
Katrin

Jannis schrieb:
> 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