geom_line displaying blank grid

242 views
Skip to first unread message

Jahan

unread,
Nov 29, 2010, 5:19:20 PM11/29/10
to ggplot2
Hi,
I am trying to plot the means of some time point measurements I have
made, but the output is just a blank grid.

time=c('p4','p7','p14','p22','p28','p35','p50')
means=c(0.638,0.786,1.292,0.220,0.450,0.570,0.438)
stuff=data.frame(time,means)
ggplot()+geom_line(data=stuff,aes(time,means))

Hopefully you will see the problem I am having. I suspect it might
have something to do with the fact that my x values are strings, but I
don't know a solution to that. Thanks in advance for your help.

James Howison

unread,
Nov 29, 2010, 7:26:04 PM11/29/10
to ggplot2
I think this has the answer:

https://groups.google.com/group/ggplot2/msg/d75a2919ccbc28d5

ggplot(data=stuff) + geom_line(aes(time,means,group=1))

Not sure if it would be possible to print a warning in this situation?

--J

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

Dennis Murphy

unread,
Nov 29, 2010, 9:26:20 PM11/29/10
to Jahan, ggplot2
Hi:

Ancient ggplot2 secret:

stuff=data.frame(time = factor(time),means)
ggplot()+geom_line(data=stuff,aes(time,means, group = 1))

The group = 1 snippet is the magic code you need to plot a line between numeric y's when the x-values are factor levels.

HTH,
Dennis

Jahan

unread,
Nov 30, 2010, 11:27:43 AM11/30/10
to ggplot2
Thanks so much! What a simple solution.

On Nov 29, 9:26 pm, Dennis Murphy <djmu...@gmail.com> wrote:
> Hi:
>
> Ancient ggplot2 secret:
>
> stuff=data.frame(time = factor(time),means)
> ggplot()+geom_line(data=stuff,aes(time,means, group = 1))
>
> The group = 1 snippet is the magic code you need to plot a line between
> numeric y's when the x-values are factor levels.
>
> HTH,
> Dennis
>
> On Mon, Nov 29, 2010 at 2:19 PM, Jahan <jahan.mohiud...@gmail.com> wrote:
> > Hi,
> > I am trying to plot the means of some time point measurements I have
> > made, but the output is just a blank grid.
>
> > time=c('p4','p7','p14','p22','p28','p35','p50')
> > means=c(0.638,0.786,1.292,0.220,0.450,0.570,0.438)
> > stuff=data.frame(time,means)
> > ggplot()+geom_line(data=stuff,aes(time,means))
>
> > Hopefully you will see the problem I am having.  I suspect it might
> > have something to do with the fact that my x values are strings, but I
> > don't know a solution to that.  Thanks in advance for your help.
>
> > --
> > 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<ggplot2%2Bunsu...@googlegroups.com>
> > More options:http://groups.google.com/group/ggplot2
Reply all
Reply to author
Forward
0 new messages