Setting for overall size (or dimensions) of a ggplot?

56 views
Skip to first unread message

Owen

unread,
Jan 8, 2009, 2:42:28 PM1/8/09
to ggplot2
Apologies in advance for the newbie question.

How can I control the size of the output plot? For example, I am
trying to make a simple dot plot to compare the distribution of values
between two categories. Because there are only two categories, most
of the resulting plot ends up being empty chart space. How can I tell
ggplot to make the plot narrower? I have looked in the book and can't
find the answer.

FYI I am using something like this, where there are only 2 values for
subj_cat:

ggplot(d2, aes(subj_cat, value)) + geom_point(position=position_jitter
(width=.02))

And thanks in advance for your assistance!

Owen

Shelby

unread,
Jan 8, 2009, 10:14:00 PM1/8/09
to ggplot2
Hi Owen,

Plot size is controlled by the dimensions of the graphic device you're
using, and in most cases R graphics (including ggplot) will rescale
themselves as well as they can to fit that. If you are just viewing
output on screen, try resizing the plot window until you like how it
looks. Then you can use the command par('din') to view the device
dimensions and use that as a guideline for setting the same dimensions
if/when you write a wrapper to send the plot to, say, a pdf file or
other saved graphics device.

Shelby

Owen

unread,
Jan 12, 2009, 6:44:39 PM1/12/09
to ggplot2
Hi Shelby,

Thank you for the help! It is an improvement, and I like your trick
to get the device dimensions.

However, the result is not exactly what I was hoping for. Resizing
the window causes all of the elements of the drawing to resize. But I
was more interested in eliminating the white space in the figure.
Because in my simple 2-category boxplot, it seems like 80% of the plot
area is "empty" background. While shrinking the display window makes
the graph smaller, it also makes the boxes of the boxplots smaller --
so the result is that ~80% of the plot area is still vacant. So I was
just wondering if there was a control within ggplot2 to fine tune the
output --- for example, to explicitly set the width of each category
column?

Thank you again,
Owen

hadley wickham

unread,
Jan 12, 2009, 7:00:55 PM1/12/09
to Owen, ggplot2
On Mon, Jan 12, 2009 at 5:44 PM, Owen <owen.s...@gmail.com> wrote:
>
> Hi Shelby,
>
> Thank you for the help! It is an improvement, and I like your trick
> to get the device dimensions.
>
> However, the result is not exactly what I was hoping for. Resizing
> the window causes all of the elements of the drawing to resize. But I
> was more interested in eliminating the white space in the figure.
> Because in my simple 2-category boxplot, it seems like 80% of the plot
> area is "empty" background. While shrinking the display window makes
> the graph smaller, it also makes the boxes of the boxplots smaller --
> so the result is that ~80% of the plot area is still vacant. So I was
> just wondering if there was a control within ggplot2 to fine tune the
> output --- for example, to explicitly set the width of each category
> column?

Maybe, I'm missing something, but don't you just want to increase the
width of the jittering? e.g.

ggplot(mtcars, aes(factor(vs), mpg)) +
geom_point(position=position_jitter(width=.2))

Hadley

--
http://had.co.nz/

Owen

unread,
Jan 12, 2009, 7:13:49 PM1/12/09
to ggplot2
Thank you, both. I was the one missing something!

It should have been obvious to me, but to summarize for others who
might be similarly puzzled: To make a "narrow" plot, increase the
width of the plot elements and then decrease the width the output
device display.

Owen
Reply all
Reply to author
Forward
0 new messages