geom_line() and missingness

143 views
Skip to first unread message

Joshua Wiley

unread,
Jun 3, 2010, 11:18:15 PM6/3/10
to ggp...@googlegroups.com
Hello All,

I am making spaghetti plots in ggplot2. I noticed that if a person is
missing data from a middle timepoint, the line for that person is
broken. Here is a simple example:

############
samp.data <- data.frame(timevar=rep(1:5, 2),
outcome=c(10,NA,7.5,7,7,7,8,7,6,8), id=rep(c(1,2),each=5))
based <- ggplot(data=samp.data, aes(x=timevar, y=outcome, group=id, colour=id))
based + geom_line() + geom_point() + scale_colour_identity()
############

In my data, some of the points with missing data after them are rather
high so those cases are especially interesting. Is there any way to
make geom_line() or geom_path() connect points across missing data? I
am also open to the idea that it is best the way it is.

Thanks,

Josh


--
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/

takahashi kohske

unread,
Jun 4, 2010, 12:27:00 AM6/4/10
to Joshua Wiley, ggp...@googlegroups.com
this is a trick but may help you:

ggplot(data=na.omit(samp.data), aes(x=timevar, y=outcome, group=id,
colour=id))+geom_line()+ geom_point() + scale_colour_identity()

2010/6/4 Joshua Wiley <jwiley...@gmail.com>:

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

Joshua Wiley

unread,
Jun 4, 2010, 2:42:43 AM6/4/10
to takahashi kohske, ggp...@googlegroups.com
It does help, thank you. I was too stuck in my approach to the
problem to have even considered using na.omit. Anyways, thanks again!

Josh

Reply all
Reply to author
Forward
0 new messages