Search code examples
rphylogenyape-phylo

How can I change the font family of tip labels in a phylogenetic tree in R ape package when saving to devSVG?


I have several phylogenetic trees imported into R from Newick format. I am using the ape package to plot the trees with plot.phylo command. I would like to be able to change the font family (not only the size, which I can do with cex, or color with col) of the tip labels to monospace. The plot command does take family argument, but nothing happens when I pass family="mono". I tried including it in par with no success either.

library(ape)
tr <- rtree(10)
plot(tr)

gives me the same as

plot(tr, family="mono")

And I would like to see a change in font.

EDIT: The font-family specification seems to work when saving graphic to png, but not devSVG. How can I save updated font to SVG?


Solution

  • Finally, a success!

    In order to be able to manipulate font-family when saving graphics in SVG format, I had to use the package grDevices and method cairo:

    library(cairo)
    svg(filename = file, width = width, height = height, family = "mono")
    

    which allows setting the family argument.

    For future reference, what did NOT work was:

    devSVG(file, width, height) and then setting family in par or plot,

    and Cairo(file, width, height, type="svg") with family in par or plot