Question: The fonts and size of a tree displayed by ggtree
2
gravatar for sunyeping
15 months ago by
sunyeping30
sunyeping30 wrote:

I'm trying to use R package ggtree to visualize my polygenic tree. I use the following codes:

library(ggtree)
library(treeio)
tree_text<-read.table("tree.nwk")
tree <-read.tree(text=as.character(tree_text$V1))
ggtree(tree, layout="daylight") + geom_tiplab(aes(angle=angle))

Some tip labels of the tree are out of the plot region and invisible (Please refer to https://www.dropbox.com/s/87gyusx7ay1xxu8/tree.pdf?dl=0). I use the dev.size("in") command to get the size of the graphic window, and it returns: [1] 5.760417 5.750000. I wish the tree can be displayed in a A4 paper size region, so I try to make a larger graphic window by:

windows(height=8,width=8)
ggtree(tree, layout="daylight") + geom_tiplab(aes(angle=angle))

but it deoesn't work. The dev.size("in") command still returns: [1] 5.760417 5.750000, and some tip labels of the tree are still out of the plot region. If I use ggsave to save the image:

p<-ggtree(tree, layout="daylight") + geom_tiplab(aes(angle=angle))    
ggsave("tree.eps",p,height=8,width=8)

it gives an error:

Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  : 
      family 'sans' not included in postscript() device

If I save the image as pdf file:

postscript("tree.pdf",family="Times",fonts="sans")

the image can be saved, but some tip labels of the tree are still out of the plot region. I try to increase the height and width value in ggsave, but the size of tree increases with the plot canvas, so invisible tip labels are always invisible

Do you know how to correct the problem and display all the complete tip labels of the tree? I will be grateful to any help!

R • 1.9k views
ADD COMMENTlink modified 15 months ago by Biostar ♦♦ 20 • written 15 months ago by sunyeping30
1

How about changing the height and width while saving in pdf format. something like this ...

ggsave(filename = "tree.pdf" , device = "pdf", width = 15, height = 30 , units = "in" , limitsize = FALSE)
ADD REPLYlink written 15 months ago by Chirag Parsania1.5k

Have you tried to just modify the label size with geom_tiplab?

ADD REPLYlink modified 15 months ago • written 15 months ago by Kevin Blighe46k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 545 users visited in the last hour