老读者,第一次发问者!
所以我有一个包含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’,结果图像被严重压缩。
我不确定如何解决这个问题。有没有人可以帮我导出一个没有压缩的高分辨率的节点标记树(最好是用正确的文件名)?
发布于 2019-02-22 08:21:13
这似乎是由于解决方案问题造成的。请注意,我无法重现您的示例,因此我可能会稍微偏离正轨(即,我不知道tree和Cairo函数从何而来--我还假设您使用的是phytools::to.matrix)。
您的解决方案2似乎运行良好,您可以使用png而不是Cairo更改文件的名称,还可以使用png中的height和width参数更改绘图尺寸
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()https://stackoverflow.com/questions/54785864
复制相似问题