如何获得R绘图窗口大小?

时间:2022-10-22 23:15:35

How can I get the size of the plot window in R? I've been using xwininfo, but there must be a function or variable in R to extract the current plot height and width.

我怎样才能得到R中绘图窗口的大小?我一直在使用xwininfo,但是在R中必须有一个函数或变量来提取当前图的高度和宽度。

UPDATE

更新

This works as a savePlot() replacement if you don't have Cairo support and you want to export plots to Windows or other 100 dpi devices:

这是一个savePlot()替换,如果您没有Cairo支持,并且您想要导出图到Windows或其他100 dpi设备:

dev.copy(png, "myplot.png", width=dev.size("px")[1], height=dev.size("px")[2], 
         res=100, bg="transparent")
dev.off()

3 个解决方案

#1


14  

You can use dev.size. Here is an example:

您可以使用dev.size。这是一个例子:

 x11()
 plot(1)
 dev.size("in")
  [1] 6.989583 6.992017

 dev.size("cm")
  [1] 17.75354 17.75972

This gets the size of your plotting window in inches and centimeters.

这将得到绘制窗口的大小(英寸和厘米)。

Similar for a png device:

png设备类似:

 png('kk.png')
 dev.size("in")
 [1] 6.666667 6.666667

Does this help you?

这帮助你吗?

#2


12  

As mentioned , using some par settings you can control control the size and the location of the plot regions. But those parameters can be a little bit confusing.( at least for me), I tried to resume some of them in this plot precising the units of each parameter. 如何获得R绘图窗口大小?

如前所述,使用一些par设置可以控制区域的大小和位置。但是这些参数可能有点令人困惑。(至少对我来说是这样),我试图在这个图中恢复其中的一些,精确地计算每个参数的单位。

PS: the original graphics is adpated from Paul Murrel Book: R graphics.

原始图形是由保罗·莫雷尔的书《R图形》添加的。

#3


2  

You should have a look to par()$fin. HTH

你应该看看平价()。HTH

#1


14  

You can use dev.size. Here is an example:

您可以使用dev.size。这是一个例子:

 x11()
 plot(1)
 dev.size("in")
  [1] 6.989583 6.992017

 dev.size("cm")
  [1] 17.75354 17.75972

This gets the size of your plotting window in inches and centimeters.

这将得到绘制窗口的大小(英寸和厘米)。

Similar for a png device:

png设备类似:

 png('kk.png')
 dev.size("in")
 [1] 6.666667 6.666667

Does this help you?

这帮助你吗?

#2


12  

As mentioned , using some par settings you can control control the size and the location of the plot regions. But those parameters can be a little bit confusing.( at least for me), I tried to resume some of them in this plot precising the units of each parameter. 如何获得R绘图窗口大小?

如前所述,使用一些par设置可以控制区域的大小和位置。但是这些参数可能有点令人困惑。(至少对我来说是这样),我试图在这个图中恢复其中的一些,精确地计算每个参数的单位。

PS: the original graphics is adpated from Paul Murrel Book: R graphics.

原始图形是由保罗·莫雷尔的书《R图形》添加的。

#3


2  

You should have a look to par()$fin. HTH

你应该看看平价()。HTH