Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Plot Window of a Particular Size

Tags:

plot

r

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

like image 266
Ryan R. Rosario Avatar asked Jan 25 '10 02:01

Ryan R. Rosario


People also ask

How do I control the size of a plot in R?

The size of plots made in R can be controlled by the chunk option fig. width and fig. height (in inches).

What is a plot window?

A plot window is the area used for creating and modifying graphs.

How do you change the size of a plot in Python?

Import matplotlib. To change the figure size, use figsize argument and set the width and the height of the plot. Next, we define the data coordinates. To plot a bar chart, use the bar() function. To display the chart, use the show() function.

How do I change the width of a plot in R?

To set plot line width/thickness in R, call plot() function and along with the data to be plot, pass required thickness/line-width value for the “lwd” parameter.


2 Answers

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

plot(1:10) dev.new(width=5, height=4) plot(1:20) 

To be more specific which units are used:

dev.new(width=5, height=4, unit="in") plot(1:20) dev.new(width = 550, height = 330, unit = "px") plot(1:15) 

edit additional argument for Rstudio (May 2020), (thanks user Soren Havelund Welling)

For Rstudio, add dev.new(width=5,height=4,noRStudioGD = TRUE)

like image 120
Shane Avatar answered Oct 02 '22 03:10

Shane


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:

  • X11
  • postscript
  • BMP, JPEG, PNG and TIFF
  • quartz (OSX only)

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

like image 44
James Thompson Avatar answered Oct 02 '22 04:10

James Thompson