ribbon on phase graphic

25 views
Skip to first unread message

Joan Lobo Prat

unread,
Jul 7, 2011, 2:29:50 AM7/7/11
to ggp...@googlegroups.com
I'm using a ribbon geom to create graphics across time such as in this example:
https://sites.google.com/site/wolfydummysite/home/phangle1.jpeg

which has been created by this code:
ggplot( data=S05RUEtablanrmmJ5,aes(x=Time,y=Phase_Angle)) +
     geom_line(aes(group=Jorang:k,color=Jorang),size=I(1)) +
     #geom_point(aes(group=Jorang,color=Jorang,),size=I(1)) +
     facet_wrap(~variable) +
     stat_summary(data=RUEtablanrmmJH,fun.data=mean_sd, geom="ribbon", alpha=0.25,aes(group=Jorang:Cond,y=Phase_Angle)) +
     stat_summary(data=RUEtablanrmmJH,fun.data=mean_sd, geom="line",aes(group=Jorang:Cond,color=Jorang:Cond,y=Phase_Angle),size=I(1))+
     scale_colour_manual(values = colorin3)

where
"mean_sd" <- function(x, mult = 1) {
  x <- na.omit(x)
  sdev <- mult * sqrt(var(x))
  mean <- mean(x)
  a=data.frame(y = mean, ymin = mean - sdev, ymax = mean + sdev)
#  a=data.frame(y = mean, ymin = mean - 20, ymax = mean + 20)
  a
}

(essentially following
http://stackoverflow.com/questions/4205428/show-standard-devation-using-geom-smooth-and-ggplot)

With these data:
https://sites.google.com/site/wolfydummysite/home/RUEtablanrmmJH.rda
https://sites.google.com/site/wolfydummysite/home/S05RUEtablanrmmJ5.rda

Now I would like to make a similar plot for the relationship between two variables ordered by time, but
cannot get the ribbon on it.

The plot with all observations an without ribbon would be:
https://sites.google.com/site/wolfydummysite/home/angvel_orang1.jpeg

which has been created by
ggplot( data=RUEtablanrmmJ5,aes(x=Orientation_Angle,y=Angular_Velocity)) +
     geom_path(aes(group=Jorang:k,color=Jorang:Cond),size=I(1)) +
     facet_wrap(~variable) +
     scale_colour_manual(values = colorin3)

As the plot is too complicated, I'd like to represent the mean and the ribbon of sd for "SFE:H" and "EFE:H" individuals
(6 individuals for each) and not the path for each individual. I've tried the following:

ggplot( data=S05RUEtablanrmmJ5,aes(x=Orientation_Angle,y=Angular_Velocity)) +
     geom_path(aes(group=Jorang:k,color=Jorang),size=I(1)) +
     facet_wrap(~variable) +
     stat_summary(data=RUEtablanrmmJH,fun.data=mean_sd, geom="ribbon", alpha=0.25,aes(group=Jorang:Cond)) +
     scale_colour_manual(values = colorin3)

https://sites.google.com/site/wolfydummysite/home/angvel_orang2.jpeg

and several variations, with no good results.

Any help appreciated!

Thanks

Joan

--
Joan Lobo Prat

BSc. Industrial Design Engineering
Escola Superior de Disseny ELISAVA (SPAIN)

MSc. Biomedical Engineering - Student
Universitat Politècnica de Catalunya - Universitat de Barcelona (SPAIN)

www.sites.google.com/site/joanloboprat/

+34 627 625 264 (SP)
+31 (0) 624 951 375 (NL)


Joan Lobo Prat

unread,
Jul 11, 2011, 5:46:27 AM7/11/11
to ggp...@googlegroups.com

Hadley Wickham

unread,
Jul 19, 2011, 5:37:34 PM7/19/11
to Joan Lobo Prat, ggp...@googlegroups.com
I think you're asking about a ribbon that doesn't travel from
left-to-right like geom_ribbon? If so, you'll need to create it
yourself using geom_polygon.

Hadley

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

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages