geom_line does not plot anything when x is a factor:

25 views
Skip to first unread message

Vitalie S.

unread,
Sep 8, 2009, 9:57:12 AM9/8/09
to ggp...@googlegroups.com

Dear Hadley,

This does not work for me:


df <- data.frame(x=factor(c(1:4)), y=1:4)
ggplot(df, aes(x, y)) + geom_line()

i.e. nothing is ploted :( Same for geom_path()

geom_point() works fine instead.

This does not look as desired feature, is it?
If so how can one plot x= aesthetic, a numeric variable, in a different
order than strictly increasing?

Thanks,
Vitalie.

Luciano Selzer

unread,
Sep 8, 2009, 10:05:04 AM9/8/09
to Vitalie S., ggp...@googlegroups.com
Hi Vitalie,
I don't know if that's a desired feature, I think Hadley can answer that. But I think it doesn't work because ggplot interprets it as being different groups. To make it work, add group=1 in the aes:

ggplot(df, aes(x, y, group = 1 )) + geom_line()

Bye
Luciano


2009/9/8 Vitalie S. <vito...@rambler.ru>

Vitalie S.

unread,
Sep 8, 2009, 10:33:35 AM9/8/09
to Luciano Selzer, ggp...@googlegroups.com
Thanks Luciano,

Indeed that works. I completely forgot that groups are taken as
intersection of all factor aesthetics. That is exactly the reason my
example works with numeric variable but not with discrete.

Cheers,
Vitalie.

On Tue, 08 Sep 2009 16:05:04 +0200, Luciano Selzer
<luciano...@gmail.com> wrote:

> Hi Vitalie,I don't know if that's a desired feature, I think Hadley can
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Reply all
Reply to author
Forward
0 new messages