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

StackOverflow https://stackoverflow.com/questions/9520448

  •  21-05-2021
  •  | 
  •  

Question

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?

Was it helpful?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top