【问题标题】:Print high quality plots in R when manipulating plot interactively交互式操作绘图时在 R 中打印高质量绘图
【发布时间】:2015-05-12 01:50:23
【问题描述】:

我需要打印一个单倍型网络以高质量地 png。但是,要按照我想要的方式绘制,我需要使用交互功能更改一些内容。当我使用png() 打印绘图时,我无法进行这些更改,因为它打印到 pdf 而不是绘图窗口。有什么办法可以将其更改为打印到绘图窗口以及 png ?

一个可重现的情节示例:

install.packages("pegas")
library(pegas)
data(woodmouse)
net <- haploNet(haplotype(woodmouse))
plot(net)
o <- replot() # interactive
## click to rearrange the network at will...
## then do a different plot using the same coordinates:
plot(net, bg = "red", labels = FALSE, show.mutation = 2)
replot(o) # not interactive

我不想在 RStudio 中使用导出按钮,因为它生成的图表质量低下。

【问题讨论】:

    标签: r plot interactive


    【解决方案1】:

    您可以使用recordPlot() 将当前绘图保存到变量中,然后将图形设备更改为png 并使用replayPlot 重播保存的绘图。例如:

    #same data as above
    o <- plot(net, bg = "red", labels = FALSE, show.mutation = 2)
    replot() # interactive - do your thing
    
    myplot <- recordPlot()
    png("recordedPlot.png")
    replayPlot(myplot)
    dev.off()
    

    【讨论】:

      猜你喜欢
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      • 2019-05-20
      • 2021-09-15
      • 1970-01-01
      • 2018-10-13
      • 1970-01-01
      • 2019-11-24
      相关资源
      最近更新 更多