need palette of topographic colors similar to topo.colors()

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

need palette of topographic colors similar to topo.colors()

bogdan romocea
Dear useRs,

I got stuck trying to generate a palette of topographic colors that
would satisfy these two requirements:
   - the pallete must be 'anchored' at 0 (just like on a map), with
light blue/lawn green corresponding to data values close to 0 (dark
blue to light blue for negative values, green-yellow-brown for
positive values)
   - the brown must get darker for higher positive values.

topo.colors() fails both requirements and AFAICS lacks any options to
control its behavior.
  #---unsatisfactory topo.colors() behavior
  topoclr <- function(tgt)
  {
  clr <- topo.colors(length(tgt))
  clr <- clr[round(rank(tgt),0)]
  plot(tgt,pch=15,col=clr)
  }
  par(mfrow=c(2,1)) ; topoclr(-50:50) ; topoclr(-20:80)

An acceptable solution would be something like this
  grayclr <- function(tgt)
  {
  tgt <- sort(tgt) ; neg <- which(tgt < 0)
  clrneg <- gray(0:length(tgt[neg])/length(tgt[neg]))
  clrpos <- gray(length(tgt[-neg]):0/length(tgt[-neg]))
  clr <- c(clrneg,clrpos)
  plot(tgt,pch=15,col=clr)
  }
  par(mfrow=c(2,1)) ; grayclr(-50:50) ; grayclr(-20:80)
if only I could make gray() use blue/brown instead of black (I tried a
couple of things but got stuck again).

Any suggestions?

Thank you,
b.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: need palette of topographic colors similar to topo.colors()

Roger Bivand
On Sat, 7 Jan 2006, bogdan romocea wrote:

> Dear useRs,
>
> I got stuck trying to generate a palette of topographic colors that
> would satisfy these two requirements:
>    - the pallete must be 'anchored' at 0 (just like on a map), with
> light blue/lawn green corresponding to data values close to 0 (dark
> blue to light blue for negative values, green-yellow-brown for
> positive values)
>    - the brown must get darker for higher positive values.
>
> topo.colors() fails both requirements and AFAICS lacks any options to
> control its behavior.
>   #---unsatisfactory topo.colors() behavior
>   topoclr <- function(tgt)
>   {
>   clr <- topo.colors(length(tgt))
>   clr <- clr[round(rank(tgt),0)]
>   plot(tgt,pch=15,col=clr)
>   }
>   par(mfrow=c(2,1)) ; topoclr(-50:50) ; topoclr(-20:80)
>
> An acceptable solution would be something like this
>   grayclr <- function(tgt)
>   {
>   tgt <- sort(tgt) ; neg <- which(tgt < 0)
>   clrneg <- gray(0:length(tgt[neg])/length(tgt[neg]))
>   clrpos <- gray(length(tgt[-neg]):0/length(tgt[-neg]))
>   clr <- c(clrneg,clrpos)
>   plot(tgt,pch=15,col=clr)
>   }
>   par(mfrow=c(2,1)) ; grayclr(-50:50) ; grayclr(-20:80)
> if only I could make gray() use blue/brown instead of black (I tried a
> couple of things but got stuck again).
>
> Any suggestions?

Use colorRampPalette() to roll your own, or something better tuned,
perhaps catenating two ramps together.

>
> Thank you,
> b.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.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, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Roger Bivand
Department of Economics
NHH Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: need palette of topographic colors similar to topo.colors()

David Ruau
In reply to this post by bogdan romocea
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

have a look at http://colorbrewer.org/
and install the package RColorBrewer

David

On Jan 7, 2006, at 20:34, bogdan romocea wrote:

> Dear useRs,
>
> I got stuck trying to generate a palette of topographic colors that
> would satisfy these two requirements:
>    - the pallete must be 'anchored' at 0 (just like on a map), with
> light blue/lawn green corresponding to data values close to 0 (dark
> blue to light blue for negative values, green-yellow-brown for
> positive values)
>    - the brown must get darker for higher positive values.
>
> topo.colors() fails both requirements and AFAICS lacks any options to
> control its behavior.
>   #---unsatisfactory topo.colors() behavior
>   topoclr <- function(tgt)
>   {
>   clr <- topo.colors(length(tgt))
>   clr <- clr[round(rank(tgt),0)]
>   plot(tgt,pch=15,col=clr)
>   }
>   par(mfrow=c(2,1)) ; topoclr(-50:50) ; topoclr(-20:80)
>
> An acceptable solution would be something like this
>   grayclr <- function(tgt)
>   {
>   tgt <- sort(tgt) ; neg <- which(tgt < 0)
>   clrneg <- gray(0:length(tgt[neg])/length(tgt[neg]))
>   clrpos <- gray(length(tgt[-neg]):0/length(tgt[-neg]))
>   clr <- c(clrneg,clrpos)
>   plot(tgt,pch=15,col=clr)
>   }
>   par(mfrow=c(2,1)) ; grayclr(-50:50) ; grayclr(-20:80)
> if only I could make gray() use blue/brown instead of black (I tried a
> couple of things but got stuck again).
>
> Any suggestions?
>
> Thank you,
> b.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)

iD8DBQFDwjXx7EoGVUIQyhERAq/0AKCPKQjlqtVl+RxVlOVlGXf2WxnvSwCfdZcD
mEpL3eSW8KI+eYFSSQZJvzM=
=/5Ix
-----END PGP SIGNATURE-----

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html