tags:

views:

393

answers:

2

How can I create a new on-screen R plot window with a particular width and height (in pixels, etc.)?

+1  A: 

This will depend on the device you're using. If you're using a pdf device, you can do this:

pdf( "mygraph.pdf", width = 11, height = 8 )
plot( x, y )

You can then divide up the space in the pdf using the mfrow parameter like this:

par( mfrow = c(2,2) )

That makes a pdf with four panels available for plotting. Unfortunately, some of the devices take different units than others. For example, I think that X11 uses pixels, while I'm certain that pdf uses inches. If you'd just like to create several devices and plot different things to them, you can use dev.new(), dev.list(), and dev.next().

Other devices that might be useful include:

There's a list of all of the devices here.

James Thompson
+4  A: 

Use dev.new(). (See this related question.)

plot(1:10)
dev.new(width=5, height=4)
plot(1:20)
Shane
I think the units are something other than pixels. I tried this example and it froze my system for 5 mins. The resulting plot window was huge as was everything displayed in it. It might be either inches or something ??
Ryan Rosario
I would suggest looking at `?Devices`, because this will vary depending on which device you use. But yes, I think that it does default to inches.
Shane
Units are in inches for onscreen display (e.g. windows or x11), and vector drawing devices (e.g. pdf, postscript), and in pixels for bitmap drawing devices (e.g. png, jpeg). Mointors usually display 72 or 96 pixels per inch, printing to paper varies from 150 to 1200 pixels per inch.
Richie Cotton
Thanks for that explanation. I wonder why there's an inconsistency there? It would be more obvious if everything was in pixels.
Shane