在空设备中打开图 [英] Open plots in a null device

查看:79
本文介绍了在空设备中打开图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用treemap程序包,并且对tmPlot如何布置绘图矩形感到满意,我想为自己的不同绘图提取网格.一个例子如下:

I'm using the treemap package and I'm happy with how tmPlot arranges plot rectangles, I want to extract the grid for my own different plots. An example is as follows:

library(treemap)
data(GNI2010)
dat <- tmPlot(GNI2010,
          index=c("continent", "iso3"),
          vSize="population",
          vColor="GNI",
          type="value")[[1]][[1]]

这样,我可以存储所需矩形的坐标.抓住的是它也产生了一个情节.我可以看到几种防止制作情节的方法:

This way I can store the coordinates of the rectangles I want. The catch is that it produces a plot as well. I can see a couple of ways to prevent the plot from being produced:

.Call("R_GD_nullDevice", PACKAGE = "grDevices")
#tmPlot here
dev.off()

这实际上会将图发送到NULL设备,但会发出警告:

This would essentially send the plot to a NULL device, but it gives a warning:

R_GD_nullDevice is deprecated and will be removed shortly 

我希望我的代码不会以这种方式破坏.我也可以删除tmPlot的相关部分,以便仅保留我想要的部分.这是可能的,但是会有点麻烦.我打算将包含此功能的函数放在包中.

I'd rather my code didn't break this way. I could also strip out the relevant parts of tmPlot so that only the parts I wanted. This is possible, but would be a bit of a nuisance. I intend that a function containing this goes inside a package.

简而言之,是否可以隐藏图形?

In short, is it possible to suppress graphics?

推荐答案

一种可行的方法是打开NULL pdf设备.我最初使用png设备尝试了此操作,该设备不起作用.

One way that seems to work is to open a NULL pdf device. I originally tried this with the png device, which doesn't work.

pdf(NULL)
dat <- tmPlot(GNI2010,
          index=c("continent", "iso3"),
          vSize="population",
          vColor="GNI",
          type="value")[[1]][[1]]
dev.off()

这篇关于在空设备中打开图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆