I have a panel containing three plots. How can I use par
to specify the width and height of the main panel so it is always at a fixed size?
Asked
Active
Viewed 1e+01k times
25

Ryan R. Rosario
- 5,114
- 9
- 41
- 56
3 Answers
34
You do that in the device, e.g.
x11(width=4, height=6)
and similarly for the file-based ones
pdf("/tmp/foo.pdf", width=4, height=6)
You can read the physical size via par("cin")
etc but not set it.

Dirk Eddelbuettel
- 360,940
- 56
- 644
- 725
-
5For completeness, `width` and `height` are specified in inch. – fbmd Dec 12 '12 at 17:23
-
As @fbmd mentioned, but also if you specify unit='in', you must also specify res='xx' where xx is 72, for example. – Patrick Williams Apr 28 '16 at 22:53
17
Neither solution works in Jupyter notebooks. Here is a general approach that works in any environment:
options(repr.plot.width=6, repr.plot.height=4)
Just keep the following function handy:
set_plot_dimensions <- function(width_choice, height_choice) {
options(repr.plot.width=width_choice, repr.plot.height=height_choice)
}
EXAMPLE
Data
x <- c(37.50,46.79,48.30,46.04,43.40,39.25,38.49,49.51,40.38,36.98,40.00,38.49,37.74,47.92,44.53,44.91,44.91,40.00,41.51,47.92,36.98,43.40)
Call function with dimensions, and draw plot:
set_plot_dimensions(6, 4)
show_distribution(x, 'test vector')
set_plot_dimensions(16, 4)
show_distribution(x, 'test vector')

Cybernetic
- 12,628
- 16
- 93
- 132
15
I usually set this at the start of my session with windows.options
:
windows.options(width=10, height=10)
# plot away
plot(...)
If you need to reset to "factory settings":
dev.off()
windows.options(reset=TRUE)
# more plotting
plot(...)

ars
- 120,335
- 23
- 147
- 134
-
8
-
5Does not work on Mac OSX: `Browse[1]> windows.options(width=10, height=10) Error in windows.options(width = 10, height = 10) : could not find function "windows.options"` – Taz Sep 06 '17 at 10:15