Robert Kubrick
Robert Kubrick

Reputation: 8753

How to get R plot window size?

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.

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:

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

Upvotes: 17

Views: 19451

Answers (3)

agstudy
agstudy

Reputation: 121618

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. enter image description here

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

Upvotes: 16

user1981275
user1981275

Reputation: 13382

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

 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('kk.png')
 dev.size("in")
 [1] 6.666667 6.666667

Does this help you?

Upvotes: 23

droopy
droopy

Reputation: 2818

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

Upvotes: 2

Related Questions