Scale y independently in each facet

270 views
Skip to first unread message

Peng Yu

unread,
Mar 2, 2012, 11:07:13 AM3/2/12
to ggplot2
Hi,

In the following example, I want to scale the y axis independently in
each facet. Some previous messages mentioned "free_y", which doesn't
seem to work as expected (I'm also not sure if I understand these
messages correctly.) Could any expert let me know what the syntax is
to scale the y axis each facet as if each facet is plotted
individually? Thanks!

library(ggplot2)

tmp=rbind(
data.frame(x=1:100, y=1:100, type='S')
, data.frame(x=1:100, y=2*(1:100), type='L')
)

qplot(x,y,data=tmp) + facet_grid(~type, scales = "free_y")

--
Regards,
Peng

Brian Diggs

unread,
Mar 2, 2012, 11:53:24 AM3/2/12
to Peng Yu, ggplot2

A facet_grid has to have the same vertical axis in each row and same
horizontal axis in each column; vertical axises can be different in
different rows, and horizontal axises can be different in different
columns. What you are trying to do is have different vertical axises in
the same row. This is because there is a single guide for a given
row/column.

facet_wrap will let you do that, though

qplot(x,y,data=tmp) + facet_wrap(~type, scales = "free_y")

Alternatively, you could grid vertically:

qplot(x,y,data=tmp) + facet_grid(type~., scales = "free_y")


--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University

Reply all
Reply to author
Forward
0 new messages