How can I create a new on-screen R plot window with a particular width and height (in pixels, etc.)?
The size of plots made in R can be controlled by the chunk option fig. width and fig. height (in inches).
A plot window is the area used for creating and modifying graphs.
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.
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.
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)
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.
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