how to adjust plot area size

2,552 views
Skip to first unread message

Herbert Jägle

unread,
Jun 5, 2012, 4:50:28 PM6/5/12
to ggplot2
I am creating multiple plots which are adjusted with grid.arrange. An
example is given below.
The plot area size depends on the size of the axis labels so two plots
in a column are not adjusted.

Is it possible to set fixed size or adjust the size of the plot area?

Thanks,
Herbert

--------------------
df.d <- data.frame(x=c(1:10), y1=c(1:10)/10, y2=c(1:10)*10000)

label=y_label_formatter <- function(x) {lab <- sprintf('%5.0f', x)}

q <- ggplot(df.d) +
geom_point(aes(x, y1)) +
scale_x_continuous(name='x-axis', limits=c(0, 11)) +
scale_y_continuous(name='y1-axis', limits=c(0, 1.1),
label=y_label_formatter)

r <- ggplot(df.d) +
geom_point(aes(x, y2)) +
scale_x_continuous(name='', limits=c(0, 11)) +
scale_y_continuous(name='y2-axis', limits=c(0, 110000),
label=y_label_formatter)

theme_set(theme_bw())
plots.l <- list(ggplotGrob(r), ggplotGrob(q))
args.l <- c(plots.l, nrow=2, ncol=1)
do.call(grid.arrange, args.l)

baptiste auguie

unread,
Jun 5, 2012, 5:05:12 PM6/5/12
to Herbert Jägle, ggplot2
You could try the following function set_panel_size() which adjusts
the gtable size,

https://gist.github.com/2877821

HTH,

baptiste
> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
Reply all
Reply to author
Forward
0 new messages