【问题标题】:plot got cut off after saving to file保存到文件后情节被切断
【发布时间】:2015-04-17 15:21:25
【问题描述】:

我的无花果在情节之外有一个很大的传说。 6行长描述当我保存它时,图例不显示。我调整了标准,但还是不行。

legend("topright", inset=c(-0.6,0),xpd=TRUE,cex=0.8,
+legend=c("A_all peaks","B_ from all peaks","C_from all peaks","A_from unique peaks",
+"B_from unique peaks","C_from unique peaks",
+"A_from overlap peaks","B_from overlap peaks","C_from overlap peaks"),
+col=c("green","red","blue","lightgreen","pink","lightblue","darkgreen","darkred","steelblue"),
+pch=c(20,20,20,20,20,20,20,20,20),bty="n")

> par()$oma
[1] 2 2 2 2 
> par()$mar
[1] 5.1 4.1 4.1 8.0

长宽保存时(尝试 800,1000 像素),没有显示图例。但是当作为短宽度()时,部分图例显示。这让我很困惑。第一张图是 500*333,第二张图是 500*800。

【问题讨论】:

    标签: r plot legend par


    【解决方案1】:

    不确定你是如何将绘图保存到文件中的,但我通常的做法是通过通常的方式在 R 中制作一个漂亮的绘图:

    plot(blah,blah,blah)
    legend(blah,blah,blah)
    

    然后,一旦我对 R 控制台的图形外观感到满意,我会使用 pdf() 或其表亲之一(jpeg()tiff() 等)将其保存到文件中,确保像这样设置宽度和高度参数:

    # set up plotting device
    pdf( {{FileName}}, 
       width = par('din')[1],
       height = par('din')[2])
    
    plot(blah,blah,blah)
    legend(blah,blah,blah)
    
    # disconnect the plotting device
    dev.off()
    

    【讨论】:

    • 您能解释一下这是如何解决问题的吗?我只是试图实现你的代码,我仍然被切断传说。
    【解决方案2】:

    使用png()tiff() 保存:

    tiff("filename",
    
    <code for plot>,
    height=5,width=7)
    dev.off()
    

    【讨论】:

      【解决方案3】:

      绘图后,尝试

      % your code…
      
      dev.copy(pdf, 'yourfile.pdf')
      dev.off()
      

      来自https://statistics.berkeley.edu/computing/saving-plots-r

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多