Specifying different breaks and limits for each facet

178 views
Skip to first unread message

kevin

unread,
Sep 18, 2009, 7:23:50 AM9/18/09
to ggplot2

Hi,

I am creating a facet plot that has non uniform scaling of the facets
on the x axis. I've set the scales parameter of facet_wrap() to
'free_x'
and would like to adjust the breaks and limits for the x scale
separately
for each individual facet, using scale_x_continuous(). Is it possible
to
do this?

Thanks,

Kevin

hadley wickham

unread,
Sep 18, 2009, 11:36:44 AM9/18/09
to kevin, ggplot2
Hi Kevin,

Not currently, unfortunately.

Hadley

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

kevin

unread,
Sep 18, 2009, 12:07:56 PM9/18/09
to ggplot2
Ok, thanks!

-Kevin

Xavier

unread,
Sep 29, 2009, 9:28:41 AM9/29/09
to ggplot2
Hi,

Related to this problem, I suppose it is also impossible to set
different axis labels for each facet. Is this feature on the todo
list? (just to know if there is a chance I might be able to use it in
a near future)

Thanks,

Xavier

hadley wickham

unread,
Sep 29, 2009, 10:12:55 AM9/29/09
to Xavier, ggplot2
> Related to this problem, I suppose it is also impossible to set
> different axis labels for each facet. Is this feature on the todo
> list? (just to know if there is a chance I might be able to use it in
> a near future)

It isn't - but where would you expect the labels to appear?

Hadley


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

Harlan Harris

unread,
Sep 29, 2009, 11:10:15 AM9/29/09
to ggplot2
And also, if you're using different axis labels for each facet, maybe
you don't want a faceted graph? Maybe you want separate graphs with
separate data (or subsets of the data)? You can always put multiple
graphs in a single figure. Section 8.4.2 of Hadley's book shows how to
do this with grid_layout() and viewport().

-Harlan

Xavier

unread,
Sep 30, 2009, 8:21:17 AM9/30/09
to ggplot2
Harlan,

You are perfectly right. However, I wasn't entirely satisfied with the
grid.layout() approach because the legend is drawn for every graph. I
can suppress the legend for all graphs but one, but then the one with
the legend appears smaller.
I sent a PM to Hadley describing this in more details, with a picture.

Thanks,

Xavier

baptiste auguie

unread,
Sep 30, 2009, 8:26:41 AM9/30/09
to Xavier, ggplot2

Xavier Chardon

unread,
Oct 5, 2009, 5:57:07 AM10/5/09
to baptiste auguie, ggplot2

Dear Baptiste,

Thank you very much for the hint, it works fine as long as I give the legend
a sufficient width in grid.layout. Otherwise the legend overlaps the graph.
For now I only tested it in the X11 driver, so it's not a problem because I
can just enlarge the graph a little, and then it's all OK!

Many thanks,

Xavier
------- End of Original Message -------

baptiste auguie

unread,
Oct 5, 2009, 6:42:58 AM10/5/09
to ggplot2
Hi,

I wonder whether it would be possible (desirable?) to define a
widthDetails.ggplot2 method (and heightDetails) so that grid knows the
size of the legend object.

Consider the following case,

library(ggplot2)
p <- qplot(data = mtcars, mpg, hp, geom = "point",
colour = cyl)
p1 <- p + opts(legend.position = "none")
p2 <- qplot(data = mtcars, wt, disp, geom = "point",
colour = cyl) + opts(legend.position = "none")
legend <- p + opts(keep = "legend_box")


legend <- ggplotGrob(legend)
top <- ggplotGrob(p1)
bottom <- ggplotGrob(p2)


layout <- grid.layout(nrow = 2, ncol = 1)

gf = grid.frame(name="gf", layout=layout)

grid.place("gf", top, row=1, col=1)
grid.place("gf", bottom, row=2, col=1)
grid.pack("gf", legend, side="right")

The space allocated by grid.pack clearly doesn't understand that only
the legend is to be drawn (in fact, I'm not sure how it infers the
size of a ggplotGrob at all).


All the best,

baptiste

hadley wickham

unread,
Oct 5, 2009, 9:51:59 AM10/5/09
to baptiste auguie, ggplot2
Yes, that's a good idea. I'd also like to make all the sizes
user-settable from options.
Hadley
--
http://had.co.nz/
Reply all
Reply to author
Forward
0 new messages