problem with scale_continuous()

7 views
Skip to first unread message

Thomas Kellermann

unread,
Mar 19, 2009, 10:40:08 AM3/19/09
to ggplot2
Hello all,

I have a small problem with scale_y_continuous() and the limits-
argument there.
To create a barplot, I used the following code, which works:

df <- data.frame(x = c("A","B","C"), y=c(2,3,2))
ggplot() + geom_bar(data=df, mapping=aes(x=x,y=y))

Setting the limits on the y-axis from 0 to 5 also works:
ggplot() + geom_bar(data=df, mapping=aes(x=x,y=y)) + scale_y_continuous
(limits=c(0,5))

But setting the limits from 1 to 5 makes the bars disappear:
ggplot() + geom_bar(data=df, mapping=aes(x=x,y=y)) + scale_y_continuous
(limits=c(1,5))

I wonder, if this is a bug or my fault...

Best regards,
Thomas

hadley wickham

unread,
Mar 20, 2009, 3:12:10 PM3/20/09
to Thomas Kellermann, ggplot2
Hi Thomas,

Have a look at coord_cartesian, particularly the xlim and ylim
parameters. When you set the scale limits, any data outside those
limits is thrown out.

Hadley
--
http://had.co.nz/
Reply all
Reply to author
Forward
0 new messages