ggplot2 y limits in barchart when + coord_flip() is used

498 views
Skip to first unread message

Daniel Murrell

unread,
Mar 16, 2012, 8:16:56 AM3/16/12
to ggplot2
Hi

I have the following problem... I want to limit the value range and it
works under normal circumstances but doesn't work after a +
coord_flip()

d <- data.frame(name = c("three","four","five"), value = c(3,4,5))
p <- ggplot(d, aes(factor(name), y=value))
p + geom_bar() + coord_cartesian(ylim=c(1,4)) + xlab("name")

# this doesn't work for me
p + geom_bar() + coord_cartesian(ylim=c(1,4)) + xlab("name") +
coord_flip()

How do I limit the y range of the graph after a +coord_flip()?

Thank you
Daniel

Winston Chang

unread,
Mar 16, 2012, 10:29:25 AM3/16/12
to Daniel Murrell, ggplot2
coord_cartesian and coord_flip are actually the same sort of thing, so in your example, you've replaced the coord_flip with coord_cartesian. This should work:

d <- data.frame(name = c("three","four","five"), value = c(3,4,5))
p <- ggplot(d, aes(factor(name), y=value))
p + geom_bar() + coord_flip(ylim=c(1,4)) + xlab("name")


Daniel

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

Daniel Murrell

unread,
Mar 16, 2012, 10:41:20 AM3/16/12
to Winston Chang, ggplot2
Hi Winston

Thanks! That works. So I must have been overriding the coord_cartesian
with the coord_flip with no parameters.

I guess I need a mapping of things that are 'the same sort of thing'
to other things to overcome problems like this in future :D

Cheers
Daniel

On Fri, Mar 16, 2012 at 2:38 PM, Daniel Murrell <dsmu...@gmail.com> wrote:
> Hi Winston
>
> Thanks! That works. So I must have been overriding the coord_cartesian
> with the coord_flip with no parameters.
>
> I guess I need a mapping of things that are 'the same sort of thing'
> to other things to overcome problems like this in future :D
>
> Cheers
> Daniel

Reply all
Reply to author
Forward
0 new messages