Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long labels #5

Closed
mbutler808 opened this issue Mar 21, 2021 · 5 comments
Closed

Long labels #5

mbutler808 opened this issue Mar 21, 2021 · 5 comments
Assignees

Comments

@mbutler808
Copy link

Hi Aaron,
This was actually the issue that really got me to hack the code. Real data exploration often involves long labels and if it is cut off, it can be a big problem to check if your regimes are correctly specified. This canʻt be fixed by making the text smaller sometimes because the region is set as a hard limit based on the node times

  rx <- range(x@times,na.rm=T)
  rxd <- 0.1*diff(rx)

In the phylogeny weʻre working on now, there are a lot of unnamed species (and long names). Sometimes we have to paste the names and sites together. We can write short codes, of course, for the species but the human brain can only process so much and with 250 taxa its really a problem.

ouch/R/plot.R

Line 79 in 3dec2ce

xlim=rx+c(-rxd,rxd),ylim=c(0,1),

My suggestion is to use the strwidth function to automatically size the plot region for the labels. This requires a cex= argument as cex is then passed to both the plot() and the text() functions. The other annoyance is that the x-axis labels then extends across the names too. I couldnʻt figure out how to limit that.

                xlim=rx+c(-rxd,rxd+max(strwidth(labels, units="figure", cex=cex))),

I generated these plots with the edits suggested and arguments

par(mar=c(2,0,0,0))
tree.plot.internal(ox, labels=labels, regimes=oreos, frame.plot=F, ladderize=F, legend=T, palette=c("black", "red", "pink", "green"), text_opts=list(pos=4, cex=.2), legend_opts=list(lwd=3, bty="n"), cex=.2)

namescut.pdf
namesok.pdf

@kingaa
Copy link
Owner

kingaa commented Mar 21, 2021

Getting the width of strings right is complicated: it depends on the font, the specific letters, etc. I looked into it awhile back and came away shaking my head. How about just giving the user an option (say, labelwidth, default = 0.1) which specifies the width of the label panels. A bit of trial-and-error will then get it right.

@mbutler808
Copy link
Author

Sure, that would work too!
I would like to update the help pages to provide more examples and explanation. Would you be OK with that? I saw that it is now autogenerated from Roxygen, so I will have to study that first. M

@kingaa kingaa self-assigned this Mar 21, 2021
@kingaa
Copy link
Owner

kingaa commented Mar 21, 2021

Happy to consider pull requests with documentation changes, as well as additional plotting options. It might also be good to add additional data sets. The primates data you sent earlier is sitting on the repo now, but not included in the package. Not sure if it is a good one.

@kingaa
Copy link
Owner

kingaa commented Mar 21, 2021

One thing to keep in mind in this is that ouch is deficient in unit tests. With each proposed change, it would be good to include tests (in the tests directory) that test the new functionality.

@kingaa
Copy link
Owner

kingaa commented Apr 28, 2021

Using the plotting branch, I can do the following. Is this an improvement? I'm not sure: seems a lot of clunkiness just to adjust label widths.

with(bimac,ouchtree(node,ancestor,time,species)) -> tr
plot(tr)
plot(tr,text_opts=list(cex=1,pos=4))
plot(tr,text_opts=list(cex=0.5,pos=4))

bimac$silly <- ifelse(
  is.na(bimac$species),
  NA_character_,
  "anamagrophilexitudinousityarpificationesqueness"
)

with(bimac,ouchtree(node,ancestor,time,silly)) -> tr
plot(tr,text_opts=list(pos=4))
plot(tr,text_opts=list(cex=0.5,pos=4))

with(bimac,ouchtree(node,ancestor,time/max(time),silly)) -> tr
plot(tr,text_opts=list(pos=4))
plot(tr,text_opts=list(cex=0.5,pos=4))

@kingaa kingaa closed this as completed Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants