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()
Use par(mai = c(bottom, left, top, right)) before the plot. It will create extra space around the plot area.
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?
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.
PS: the original graphics is adpated from Paul Murrel Book: R graphics.
You should have a look to par()$fin. HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With