Facet_wrap, free_y, scale starting from zero?

4,957 views
Skip to first unread message

johannes rara

unread,
Aug 5, 2010, 3:45:47 AM8/5/10
to ggplot2
Hi,

When using facet_wrap and free y axis scale, how to determine that
every scale will have to strart from zero?

E.g. how using this example I can change that every free scale will
start from zero?

library(ggplot2)
p <- qplot(displ, hwy, data = mpg)
p + facet_wrap(~ cyl, scales = "free_y")

-J

Dennis Murphy

unread,
Aug 5, 2010, 10:26:48 AM8/5/10
to johannes rara, ggplot2
Hi:

Is this what you had in mind?

p + facet_wrap(~ cyl, scales = "free_y") + expand_limits(x = 0, y = 0)

HTH,
Dennis


--
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

johannes rara

unread,
Aug 5, 2010, 12:52:45 PM8/5/10
to Dennis Murphy, ggplot2
Exactly, thanks!

-J

2010/8/5 Dennis Murphy <djm...@gmail.com>:

Richard Nixon

unread,
Aug 6, 2010, 5:33:08 PM8/6/10
to ggplot2
Hi,

Looks like the problem was that I was not using the latest version of
ggplot2. The plot behaves as expected under version 0.8.8, and needs
the data set below (data in the original post does not work with
0.8.8).

p <- ggplot(demo.data, aes(x = DATE, y = LINE.TYPE)) +
geom_line() +
geom_point(aes(shape = POINT.TYPE))

p + facet_wrap(~ ID)

demo.data <- structure(list(ID = structure(c(3L, 3L, 4L, 4L, 4L, 4L,
6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 1L, 1L, 1L, 1L, 5L, 5L, 8L, 8L, 2L, 2L,
2L, 2L, 7L, 7L, 7L, 7L), .Label = c("0324", "1734", "1790", "6541",
"6717", "6759", "7646", "9898"), class = "factor"), DATE =
structure(c(11565,
11865, 10920, 11220, 10920, 11220, 12005, 13207, 13298, 13598,
12430, 12730, 12005, 13207, 13075, 13375, 13075, 13375, 11955,
12255, 14469, 14769, 14609, 14909, 14609, 14909, 13843, 14143,
13843, 14143), class = "Date"), POINT.TYPE = structure(c(3L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 2L, 2L, 3L, 4L, 3L, 3L, 3L,
3L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L), .Label = c("1",
"2", "3", "4"), class = "factor"), LINE.TYPE = structure(c(4L,
4L, 2L, 2L, 4L, 4L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 1L, 1L, 4L,
4L, 2L, 2L, 2L, 2L, 1L, 1L, 4L, 4L, 1L, 1L, 4L, 4L), .Label = c("D",
"C", "B", "A"), class = "factor")), .Names = c("ID", "DATE",
"POINT.TYPE", "LINE.TYPE"), row.names = c(NA, 30L), class =
"data.frame")
Reply all
Reply to author
Forward
0 new messages