简体   繁体   English

无法使用颜色将系统发育树保存为pdf

[英]Can't save phylogenetic tree to pdf with color

I am trying to save my phylogenetic tree with coloured branches using discrete data, everytime I do the pdf() function and then try to open it I get a pdf error. 我每次尝试执行pdf()函数并尝试打开它时,都使用离散数据用彩色分支保存我的进化树,然后出现pdf错误。 This is the code I am using 这是我正在使用的代码

tree = read.nexus("phylo.1966")
tree3<-read.csv("BBS1966.2015.pgls.csv",row.names = 1)
tree3<-setNames(tree3[,1],rownames(Nesting))
cols<-setNames(palette()[1:6],levels(Nesting))
Nesttree<-make.simmap(drop.tip(tree2, setdiff(tree2$tip.label,names(Nesting))),Nesting, model = "SYM"
plotTree(Nesttree,cols,type="fan",fsize=0.8,lwd=3,ftype="i")
add.simmap.ledgend(colors=cols,x=0.9*par()$usr[1],y=0.9*par()$usr[4],prompt=FALSE,fsize=0.9)
pdf("Nesting1.pdf", width = 100, height = 100)
dev.off()

however, if I place the pdf function before the plotTree function it will open but no color is added to the tree. 但是,如果我将pdf函数放置在plotTree函数之前,它将打开但没有颜色添加到树中。 tree2 is from a code used previously which just took my original tree and added the subspecies to make a new tree. tree2来自先前使用的代码,该代码只接受了我原来的树,并添加了亚种以创建一棵新树。

Also if I try to manually save the plot as a jpeg the size of the tree remains the same but the plot area will change to the size I chose, so it looks small and super crowded. 另外,如果我尝试将图手动保存为jpeg,则树的大小将保持不变,但图区域将更改为我选择的大小,因此它看起来很小且非常拥挤。

Thank you for any help. 感谢您的任何帮助。 This is the image I produce after using the corrected code 这是我使用更正的代码后生成的图像

As I commented you can manually adjust the width and height of images if you images is crowded. 正如我评论的那样,如果图像拥挤,您可以手动调整图像的宽度和高度。 You can use any device in place of jpeg (eg PDF) for pdf however you don't need to set height or width. 您可以使用任何设备代替jpeg (例如PDF)来获取pdf,但是您无需设置高度或宽度。

jpeg("filename.jpeg", height = 1080, width =1080)
plotTree(Nesttree,cols,type="fan",fsize=0.8,lwd=3,ftype="i")
add.simmap.legend(colors=cols,x=0.9*par()$usr[1],y=0.9*par()$usr[4],prompt=FALSE,fsize=0.9)
dev.off()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM