长期阅读者,首次申请者!
因此,我有一个系统发育树,其中包含18个提示(A-Q)和17个内部节点。内部节点用一些彩色的饼标记,如下所示:
plot(tree, cex = 0.8, label.offset= 1)
mbv <- c(1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0)
nodelabels(pie = mbv, piecol = c("black", "white"), cex = 0.8)
trait <- c(0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1)
names(trait)<-tree$tip.label
tiplabels(pie = to.matrix(trait, sort(unique(trait))), piecol = c("black", "white"),
cex = 0.4)
我正在尝试导出这棵树的高分辨率PNG或Tiff图像,但是有问题。
原始代码:
Cairo(filename='SpeciesTree_withBins.png', type="png", res=300)
par(mar=c(1,1,1,1))
{plot(tree, cex = 0.8, label.offset= 1)
mbv <- c(1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0)
nodelabels(pie = mbv, piecol = c("black", "white"), cex = 0.8)
trait <- c(0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1)
names(trait)<-tree$tip.label
tiplabels(pie = to.matrix(trait, sort(unique(trait))), piecol = c("black", "white"),
cex = 0.4)}
dev.off()
这导致了以下错误:
Error in symbols(xpos, ypos, circles = radius, inches = FALSE, add = TRUE, :
plot.new has not been called yet
尝试的解决方案1:
Cairo(filename='SpeciesTree_withBins.png', type="png", res=300)
{plot(tree, cex = 0.8, label.offset= 1)
mbv <- c(1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0)
nodelabels(pie = mbv, piecol = c("black", "white"), cex = 0.8)
trait <- c(0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1)
names(trait)<-tree$tip.label
tiplabels(pie = to.matrix(trait, sort(unique(trait))), piecol = c("black", "white"),
cex = 0.4)}
dev.off()
哪个给了我一个不同的错误:
Error in plot.new() : figure margins too large
尝试的解决方案2:
Cairo(filename='SpeciesTree_withBins.png', type="png", res=300)
par(mar=c(1,1,1,1))
{plot(tree, cex = 0.8, label.offset= 1)
mbv <- c(1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0)
nodelabels(pie = mbv, piecol = c("black", "white"), cex = 0.8)
trait <- c(0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1)
names(trait)<-tree$tip.label
tiplabels(pie = to.matrix(trait, sort(unique(trait))), piecol = c("black", "white"),
cex = 0.4)}
dev.off()
这确实产生了一个PNG,但是名称为“ plot”而不是“ SpeciesTree_withBins”,并且结果图像被严重压缩。
我不确定如何解决此问题。有人可以帮助我导出未压缩的,带有节点标记的高分辨率树(最好使用正确的文件名)吗?
答案 0 :(得分:1)
这似乎是由于解决问题所致。请注意,我无法重现您的示例,因此我在这里可能会有点偏离(即,我不知道tree
和Cairo
函数的来源-我还假设您正在使用phytools::to.matrix
。
您的解决方案2似乎运行良好,您可以使用png
而不是Cairo
来更改文件名,还可以使用height
和width
中的png
个参数:
library(ape)
library(phytools)
## Making a random tree
tree <- rtree(18)
## Setting up the png output file
## you might want to change the width and height here!
png(filename = "SpeciesTree_withBins.png", res = 300,
width = 800, height = 800)
## The margin definition
par(mar = c(1,1,1,1))
## Some tree parameters
mbv <- c(1,1,1,1,1,1,1,1,1,0,0,1,1,1,0,0,0)
trait <- c(0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1)
names(trait) <- tree$tip.label
## Plotting the tree
plot(tree, cex = 0.8, label.offset= 1)
nodelabels(pie = mbv, piecol = c("black", "white"), cex = 0.8)
tiplabels(pie = to.matrix(trait, sort(unique(trait))),
piecol = c("black", "white"),cex = 0.4)
## Saving the file
dev.off()