首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >导出高分辨率、节点标记的系统发育树

导出高分辨率、节点标记的系统发育树
EN

Stack Overflow用户
提问于 2019-02-20 19:57:59
回答 1查看 365关注 0票数 0

老读者,第一次发问者!

所以我有一个包含18个提示(A-Q)和17个内部节点的系统发育树。内部节点用一些彩色馅饼标记,如下所示:

代码语言:javascript
复制
    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图像的这棵树,但我有问题。

原始代码:

代码语言:javascript
复制
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()

这导致了以下错误:

代码语言:javascript
复制
Error in symbols(xpos, ypos, circles = radius, inches = FALSE, add = TRUE,  : 
  plot.new has not been called yet

尝试的解决方案1:

代码语言:javascript
复制
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()

这给了我一个不同的错误:

代码语言:javascript
复制
 Error in plot.new() : figure margins too large 

尝试的解决方案2:

代码语言:javascript
复制
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’,结果图像被严重压缩。

Squashedplot

我不确定如何解决这个问题。有没有人可以帮我导出一个没有压缩的高分辨率的节点标记树(最好是用正确的文件名)?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-22 08:21:13

这似乎是由于解决方案问题造成的。请注意,我无法重现您的示例,因此我可能会稍微偏离正轨(即,我不知道treeCairo函数从何而来--我还假设您使用的是phytools::to.matrix)。

您的解决方案2似乎运行良好,您可以使用png而不是Cairo更改文件的名称,还可以使用png中的heightwidth参数更改绘图尺寸

代码语言:javascript
复制
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()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54785864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档