KlausVigo / phangorn

Phylogenetic analysis in R
http://klausvigo.github.io/phangorn/
205 stars 38 forks source link

rotate labels #162

Closed locusclassicus closed 8 months ago

locusclassicus commented 9 months ago

First of all, thanks for the useful package! My problem is with labels which are now all horizontal, and therefore not legible. I can find to way to rotate them (see picture). Ideally they should be rotated at the same angle as the edge

image

This one was made with:

plot(nnet,
     type = "equal angle", 
     tip.color = nnet$dial_lab, 
     edge.color = "grey20",
)
KlausVigo commented 8 months ago

Dear @locusclassicus, in the development version from github you can use the additional argument direction="axial" to just do that. Regards, Klaus

tomas-fer commented 6 months ago

Thank you for this function, however, there is a problem with plotting axial labels outside plot margins. Is there any easy fix?

KlausVigo commented 6 months ago

Hi @tomas-fer, there is! You can get the x and y limits of the plot the following way:

plot(nnet, direction="axial")
lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv)
lastPP$x.lim
lastPP$y.lim

You can increase the margins using the xlim and ylim arguments as usual , for example:

plot(nnet, direction="axial", xlim=c(-10,10), ylim=c(-10,10))

I made some small changes recently, so you might want to try the development version.

tomas-fer commented 6 months ago

Dear Klaus,

thank you for your answer. However, as I understand your suggestion, it requires playing with the xlim and ylim parameters, right? I am still thinking about an ‘automated’ xlim and ylim settings that would always result in correct plotting…

My solution (also not ‘automated’) was to set large plot margins and allow plotting outside margins before plot command, e.g.,

a=8 par(mar=c(a,a,a,a), xpd=T) plot(nnet, direction="axial")

Excessive white margins can be removed later (e.g., from the resulting PDF)…

Another useful function would be to allow label offset from tips (like offset in tiplabels() with trees).

Thank you for very useful functions in phangorn.

Best wishes, Tomas

KlausVigo commented 5 months ago

Dear @tomas-fer, I will try to get better defaults, when I have time. One can use tiplabels() with plot.networx already, but it needs some fiddling within ape code so that both functions understand each other better. As plot.networx is based on plot.phylo, but ape does not know about plot.networx or networx objects. Regards, Klaus