How do I go about making the width of a graph narrower by adjusting the margins of the plotting device?
For example with:
plot(1:40)
Is there a parameter I can use to control the margins?
How do I go about making the width of a graph narrower by adjusting the margins of the plotting device?
For example with:
plot(1:40)
Is there a parameter I can use to control the margins?
par
is used to set the graphical parameters.
mar
gives the number of lines of margin to be specified on the four sides of the plot. A numerical vector of the form c(bottom, left, top, right).
To make the plot narrower:
par(mar=c(5,10,5,10))
plot(1:40)
In addition to the answers given, other plotting devices, like png()
and pdf()
have width
and height
options.
png(filename=..., width=200, heigth=800, units="px")
plot(1:40)
dev.off()
As your question is almost opaque as to what you mean by "width" - the width of the device, the width of the region containing the data points, etc? - I'll put out another option, parameter pin
:
layout(1:2)
plot(1:10)
op <- par(pin = c(3,2)) ## 3" by 2" high
plot(1:10)
par(op)
layout(1)
which produces
when used with
png("par-pin-plot.png", units = "in", height = 8, width = 5, res = 100)
...plot code...
dev.off()
If you then use parameter mai
to set the margin sizes in inches as well, you can control the exact width of the plot region, margins, and overall figure.