Quantcast
Channel: Phylogenetic Tools for Comparative Biology
Viewing all articles
Browse latest Browse all 802

Changing the color ramp in contMap or densityMap

$
0
0

I recently received the following question:

"Would it be possible in contMap to specify our own color ramp instead of stuck with the default red-to-blue?"

This cannot yet be done automatically, but it is not too hard. Here are a couple of examples. Note that they also apply equally to objects created using densityMap.

> ## first create simulated tree & data
> tree<-pbtree(n=26,tip.label=LETTERS[26:1])
> x<-fastBM(tree)
> ## build object of class "contMap"
> obj<-contMap(tree,x,plot=FALSE)
> obj
Object of class "contMap" containing:

(1) A phylogenetic tree with 26 tips and 25 internal nodes.

(2) A mapped continuous trait on the range (-4.458, 2.5).

> ## default colors
> plot(obj)
> ## what is the length of the current color ramp?
> n<-length(obj$cols)
> ## change to grey scale
> obj$cols[1:n]<-grey(0:(n-1)/(n-1))
> plot(obj)
> ## change to blue -> red
> obj$cols[1:n]<-colorRampPalette(c("blue","red"), space="Lab")(n)
> plot(obj)

That's it!


Viewing all articles
Browse latest Browse all 802

Trending Articles