Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get R plot window size?

Tags:

plot

r

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()
like image 285
Robert Kubrick Avatar asked Jun 20 '13 12:06

Robert Kubrick


People also ask

How do I increase plot area in R?

Use par(mai = c(bottom, left, top, right)) before the plot. It will create extra space around the plot area.


3 Answers

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?

like image 108
user1981275 Avatar answered Oct 15 '22 08:10

user1981275


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.

like image 26
agstudy Avatar answered Oct 15 '22 07:10

agstudy


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

like image 20
droopy Avatar answered Oct 15 '22 06:10

droopy