I am trying to visualize the results of a phylogenetic least squares regression using ape
and phytools
. Specifically, I have been trying to create a regression equation for predictive purposes, and I am looking at how much phylogenetic signal influences the residuals (and hence the accuracy of the equation). I have been using a code somewhat similar to the following to plot the results (albeit here retooled for dummy data).
library("ape")
library("phytools")
orig_tree<-rtree(n=20)
plot(orig_tree)
values<-data.frame("residuals"=runif(20,min=-1,max=1),row.names=orig_tree$tip.label)
values<-setNames(values$residuals,rownames(values))
residualsignalfit<-fastAnc(orig_tree,values,vars=TRUE,CI=TRUE)
obj<-contMap(orig_tree,values,plot=FALSE)
plot(obj,fsize=.25)
However, the problem comes in that I have a few species that exhibit extremely high residuals relative to the rest of the dataset. Because the minimum and maximum values of the color gradient are set to the minimum and maximum values of the actual column, this washes out all the contrast between 90% of the dataset to visualize the few extreme outlier values. Below is code that reproduces an example of what I mean compared to obj
above.
values2<-values
values2[6]<--2
values2[7]<-2
residualsignalfit2<-fastAnc(orig_tree,values2,vars=TRUE,CI=TRUE)
obj2<-contMap(orig_tree,values2,plot=FALSE)
plot(obj2,fsize=.25)
This causes the figure to make it seem as though there is much less phylogenetic signal than there really is because it colors all but the most extreme outlier points to be similar in color.
I am trying to figure out a way to set the minimum and maximum of the color gradient so that any value ≤ -1 is the maximum possible red value and any value ≥ 1 is the maximum possible blue value, thereby allowing greater contrast in the rest of the residuals. I tried using the command
plot(obj2,fsize=.25,lims=c(-1,1))
but as you can see from this code this does nothing. I know ggplot2
has an option to rescale the color gradient based on user-inputted values, but I can't seem to figure out how to make phylogeny objects from ape
or phytools
get plotted in ggplot2.
Given this, is there any way to manipulate the color gradient pattern in ape/phytools such that one can arbitrarily set the maximum and minimum boundaries for the color gradient?