thej022214 / corHMM

Fits a generalized form of the covarion model that allows different transition rate classes on different portions of a phylogeny by treating rate classes as “hidden” states in a Markov process.
11 stars 13 forks source link

plotRECON legend specs #53

Open HedvigS opened 1 year ago

HedvigS commented 1 year ago

Is there a way of removing the legend in plotRECON, or explicitly paste what they should be? By default, I get it as "1, R1" and since they're both in the same rate category I'd prefer to either set the labels myself (e.g. just "1"), or remove the legend altogether. ML_gray_mcct_-GB133

jamie-thompson commented 2 months ago

Is it possible to move the legend?

jcoliver commented 2 months ago

As of now, plotRECON() is fairly hard-coded and does not allow moving the legend. However, the function itself is fairly short, so you could, instead of calling plotRECON(), replicate the code that function uses and modify legend through the call to legend().

The plotRECON() function (also available in the R folder):

plotRECON <- function(phy, likelihoods, piecolors=NULL, cex=0.5, pie.cex=0.25, file=NULL, height=11, width=8.5, show.tip.label=TRUE, title=NULL, ...){
    if(is.null(piecolors)){
        piecolors=c("white","black","red","yellow","forestgreen","blue","coral","aquamarine","darkorchid","gold","grey","yellow","#3288BD","#E31A1C")
    }
    if(!is.null(file)){
        pdf(file, height=height, width=width,useDingbats=FALSE)
    }
    plot(phy, cex=cex, show.tip.label=show.tip.label, ...)

    if(!is.null(title)){
        title(main=title)
    }
    nodelabels(pie=likelihoods,piecol=piecolors, cex=pie.cex)
    states <- colnames(likelihoods)
    legend(x="topleft", states, cex=0.8, pt.bg=piecolors,col="black",pch=21);

    if(!is.null(file)){
        dev.off()
    }
}

A short bit of code that does what the function does, but putting legend in bottom right (you'll need to make sure the required objects (phy, likelihoods, states) exist (or change the names to match your data)):

piecolors=c("white","black","red","yellow","forestgreen","blue","coral","aquamarine","darkorchid","gold","grey","yellow","#3288BD","#E31A1C")
plot(phy)
nodelabels(pie=likelihoods,piecol=piecolors)
states <- colnames(likelihoods)
legend(x="bottomright", states);