【发布时间】:2019-08-04 20:18:04
【问题描述】:
我正在尝试使用离散数据保存带有彩色分支的系统发育树,每次我执行 pdf() 函数然后尝试打开它时都会收到 pdf 错误。 这是我正在使用的代码
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()
但是,如果我将 pdf 函数放在 plotTree 函数之前,它将打开,但不会向树添加颜色。 tree2 来自之前使用的代码,该代码仅采用了我的原始树并添加了亚种以制作一棵新树。
此外,如果我尝试手动将绘图保存为 jpeg,树的大小将保持不变,但绘图区域会更改为我选择的大小,因此它看起来很小而且非常拥挤。
感谢您的帮助。 This is the image I produce after using the corrected code
【问题讨论】:
-
您可以手动调整图像大小
?jpeg。使用width和height。当您在绘制绘图后打开pdf时,您的代码将无法工作。您要执行的顺序是打开设备(pdf、jpeg 等)、运行绘制图像的代码、关闭设备 (dev.off()) -
@George 你的评论应该是一个答案,看起来它解决了问题。