首页 文章

我们可以在seqtreedis()函数调用中更改图像的分辨率吗?

提问于
浏览
1

我使用R软件包TraMineR中的seqtreedis()函数生成树图像,但默认分辨率为72 dpi . 我需要创建300 dpi图像 . 是否有可能在seqtreedis()函数调用中使用类似“res”参数?

感谢帮助

1 回答

  • 0

    您可以通过传递 device.args 参数(将被视为 ... 列表的元素)来控制 seqtreedisplay 函数生成的输出文件的分辨率 .

    device.args 参数应该是将传递给已使用设备的参数列表( jpeg 时为 image.format="jpg" ,否则为 png ) .

    要获得300 dpi分辨率,您需要设置 res=300 ,还要增加 widthheight .

    我用 mvad 数据说明:

    data(mvad)
    ## Defining a state sequence object
    mvad.seq <- seqdef(mvad[, 17:86])
    
    ## Growing a seqtree using Hamming distances:
    seqt <- seqtree(mvad.seq~ male + Grammar + funemp + gcse5eq + fmpr + livboth,
                    data=mvad, R=1000, pval=0.05, seqdist.arg=list(method="HAM"))
    
    ## Generating the plot as a 300 dpi image in mytree.jpg
    seqtreedisplay(seqt, filename = "mytree.jpg", type="d", border=NA, image.format = "jpg", 
          device.args=list(width=480*300/72, height=480*300/72, res=300))
    

    Below is my previous answer that does not work because seqtreedisplay internally first generates texts and plots in bitmap format before saving them in the image.format.


    解决方案是为seqtreedisplay的结果选择矢量格式(例如pdf或eps),然后将该矢量文件转换为具有所需分辨率的光栅格式 .

    假设您已经安装 ImageMagickImageMagick 依赖于 ImageMagick 转换为/从pdf或eps转换),您可以使用 TraMineRextrasconvert.g 函数进行此转换 . 我在下面使用 mvad 数据说明:

    ## Drawing the tree as a pdf file and converting into jpeg
    seqtreedisplay(seqt, filename = "mytree.pdf", type="d", border=NA, image.format = "pdf")
    path <- getwd() ## retrieve the path
    convert.g(path = path, fileroot = "mytree", from = "pdf", to = "jpeg",
              options = "-units PixelsPerInch -density 300x300")
    

    生成的jpeg文件将位于当前文件夹的 jpeg 子目录中 .

相关问题