several issues with ggplot2 and grid arrange

1,136 views
Skip to first unread message

Alberto Conti

unread,
Dec 26, 2011, 5:56:47 PM12/26/11
to ggplot2
Hi,

I am relatively new to ggplot2, but I have searched the answers to the
following issues/questions a bit and I have not come up adequate
answers.

1. Labels
When I make a plot the x-axis and y-axis label is not centered. This
does not produce publication quality plots.
How do I center it by default (and forever?)

2. When I use grid.arrange to plot 4 plots on the same page, the
output text for labels and title is different than what I see on the
screen (in general much larger). Why? Output is PDF. The result does
not produce publication quality plots.

3. When I use grid.arrange and I add a title to each column (on a 2 x
2 plot, say), the plots in the first row are smaller (to compensate
for the title) than the bottom ones. Again, the result does not
produce publication quality plots. Is there a way to fix this?

4. My plots share the same x axis (each column) and y axis (each row),
yet I could not find a way to remove the inter-plot spaces.
I looked into using viewports, but it seems just overly complex for no
reason.
One not simply allow viewpoints to take npc as a negative (say -1) and
this would remove the space in the x or y direction?

5. Finally, some perhaps silly question: once I find a package, like
gridExtra, what is the best place to find how to use it properly?
Detailed examples of its functions?

Hadley Wickham

unread,
Dec 27, 2011, 12:05:40 PM12/27/11
to Alberto Conti, ggplot2
> 1. Labels
> When I make a plot the x-axis and y-axis label is not centered. This
> does not produce publication quality plots.
> How do I center it by default (and forever?)

This is fixed in the development version.

> 2. When I use grid.arrange to plot 4 plots on the same page, the
> output text for labels and title is different than what I see on the
> screen (in general much larger). Why? Output is PDF. The result does
> not produce publication quality plots.

Please provide a reproducible example.

> 5. Finally, some perhaps silly question: once I find a package, like
> gridExtra, what is the best place to find how to use it properly?
> Detailed examples of its functions?

In theory, you should get such documentation from package?gridExtra,
but not everyone has written a package documentation page. You can
always get a list of functions in the package with help(package =
ggExtra)

Hadley

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Alberto Conti

unread,
Dec 27, 2011, 12:28:28 PM12/27/11
to Hadley Wickham, ggplot2
> 1. Labels
> When I make a plot the x-axis and y-axis label is not centered. This
> does not produce publication quality plots.
> How do I center it by default (and forever?)

This is fixed in the development version.


awesome when will it be pushed out?
 
> 2. When I use grid.arrange to plot 4 plots on the same page, the
> output text for labels and title is different than what I see on the
> screen (in general much larger). Why? Output is PDF. The result does
> not produce publication quality plots.

Please provide a reproducible example.

take a look. PNG is screenshot, PDF is output. Nothing was changed. I'm on a mac using r-studio

 

> 5. Finally, some perhaps silly question: once I find a package, like
> gridExtra, what is the best place to find how to use it properly?
> Detailed examples of its functions?

In theory, you should get such documentation from package?gridExtra,
but not everyone has written a package documentation page.  You can
always get a list of functions in the package with help(package =
ggExtra)

very useful, thanks!

-Alberto

baptiste auguie

unread,
Dec 27, 2011, 4:14:54 PM12/27/11
to albert...@gmail.com, ggplot2
On 28 December 2011 06:28, Alberto Conti <albert...@gmail.com> wrote:
>> > 1. Labels
>> > When I make a plot the x-axis and y-axis label is not centered. This
>> > does not produce publication quality plots.
>> > How do I center it by default (and forever?)
>>
>> This is fixed in the development version.
>>
>
> awesome when will it be pushed out?
>
>>
>> > 2. When I use grid.arrange to plot 4 plots on the same page, the
>> > output text for labels and title is different than what I see on the
>> > screen (in general much larger). Why? Output is PDF. The result does
>> > not produce publication quality plots
>>
>> Please provide a reproducible example.
>
>
> take a look. PNG is screenshot, PDF is output. Nothing was changed. I'm on a
> mac using r-studio

That's not a reproducible example, please see http://gist.github.com/270442

In your screenshot Rstudio uses its own output device; I suspect this
is the reason you see a different font size with pdf. Note that this
issue is not related to ggplot2 so it may not be the best place to ask
for help.

For your other layout issues, I think your best option is to use a
dummy facetting variable; that will take care of the spacing between
panels, as well as aligning the axes. See
https://github.com/hadley/ggplot2/wiki/Align-two-plots-on-a-page for
an example.

>
> http://dl.dropbox.com/u/473509/R_examples.zip
>
>>
>>
>> > 5. Finally, some perhaps silly question: once I find a package, like
>> > gridExtra, what is the best place to find how to use it properly?
>> > Detailed examples of its functions?
>>
>> In theory, you should get such documentation from package?gridExtra,
>> but not everyone has written a package documentation page.  You can
>> always get a list of functions in the package with help(package =
>> ggExtra)
>
>
> very useful, thanks!
>
> -Alberto
>
>
>
>>
>>
>> Hadley
>>
>> --
>> Assistant Professor / Dobelman Family Junior Chair
>> Department of Statistics / Rice University
>> http://had.co.nz/
>
>

> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

Sean O'Riordain

unread,
Dec 30, 2011, 4:27:36 AM12/30/11
to baptiste auguie, Hadley Wickham, ggplot2
Hi Baptiste, Hadley,

> For your other layout issues, I think your best option is to use a
> dummy facetting variable; that will take care of the spacing between
> panels, as well as aligning the axes. See
> https://github.com/hadley/ggplot2/wiki/Align-two-plots-on-a-page for
> an example.

I've just run this example in the dev version of ggplot2 and it has
changed colour from red/blue to blue - is this intentional?

I'm also getting error messages at the end when I try to print the
graph. i.e. this is what I did...

library(devtools)
dev_mode()
library(ggplot2)
x <- seq(1992, 2002, by=2)
d1 <- data.frame(x=x, y=rnorm(length(x)))
xy <- expand.grid(x=x, y=x)
d2 <- data.frame(x=xy$x, y=xy$y, z= jitter(xy$x + xy$y))
d1$panel <- "a"
d2$panel <- "b"
d1$z <- d1$x
d <- rbind(d1, d2)
p <- ggplot(data = d, mapping = aes(x = x, y = y))
p <- p + facet_grid(panel~., scale="free")
p <- p + layer(data= d1, geom = c( "line"), stat = "identity")
p <- p + layer(data=d2, mapping=aes(colour=z, fill=z), geom
=c("tile"), stat = "identity")
p

Then I get...

> p
Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf

Kind regards,
Sean

hadley wickham

unread,
Dec 30, 2011, 9:36:00 AM12/30/11
to Sean O'Riordain, baptiste auguie, ggplot2
>> For your other layout issues, I think your best option is to use a
>> dummy facetting variable; that will take care of the spacing between
>> panels, as well as aligning the axes. See
>> https://github.com/hadley/ggplot2/wiki/Align-two-plots-on-a-page for
>> an example.
>
> I've just run this example in the dev version of ggplot2 and it has
> changed colour from red/blue to blue - is this intentional?

Yes, I've been meaning to change that for a while - the colour scale
should now look clearly ordered.

> I'm also getting error messages at the end when I try to print the
> graph. i.e. this is what I did...

Those are warning messages, and have just been fixed.

Reply all
Reply to author
Forward
0 new messages