【问题标题】:Can't save phylogenetic tree to pdf with color无法将系统发育树保存为带颜色的pdf
【发布时间】: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。使用widthheight。当您在绘制绘图后打开 pdf 时,您的代码将无法工作。您要执行的顺序是打开设备(pdf、jpeg 等)、运行绘制图像的代码、关闭设备 (dev.off())
  • @George 你的评论应该是一个答案,看起来它解决了问题。

标签: r pdf rstudio ape-phylo


【解决方案1】:

正如我所评论的,如果图像拥挤,您可以手动调整图像的宽度和高度。您可以使用任何设备代替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()

【讨论】:

  • 我尝试了您对 pdf 的建议,它会打开,但树上没有颜色,树全是黑色的。当我使用 jpeg 尝试时也会发生这种情况
  • @BirdNerd171 您能否详细说明plotTree 函数和add.simmap.legend 函数的来源。如果只运行那些函数剂量 R 画一棵彩色树?刚刚注意到您的函数名称中有一个错字(我假设),在您的代码中它是 add.simmap.ledgend 不应该是 add.simmap.legend
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多