[R] ggplot / reshape: basic usage

hadley wickham h.wickham at gmail.com
Thu Jan 24 02:34:16 CET 2008


On Jan 23, 2008 10:44 AM, baptiste Auguié <ba208 at exeter.ac.uk> wrote:
> Hi,
>
> I've been trying to do the following simple thing: given a data.frame,
>
> > library(reshape)
> > library(ggplot2)
> >
> > df <- data.frame(x=c(1:10),y=sin(1:10),z=cos(1:10))
> > dfm<-melt(df, id=c("x"), measured=c("y","z"))
>
>
> i want to plot  y and z against x, and add vertical errorbars to the
> points corresponding to the standard deviation of y and z respectively.
>
> I tried the following, inspired by some previous post in the list,
>
> > se <- function(x) sd(x)/sqrt(length(x))
> > means <- cast(dfm, variable~., function(x) c(se = se(x)))
> >
> > qplot(value,x, data=means, colour=variable, min = value - se, max =
> >  value + se, geom=c("point","errorbar"))
>
>
> but this fails, as I obviously don't get the philosophy behind the
> "cast" function.

Could you explain a little more what you are trying to do?  There is
one s.e. for y and one z, but what are you trying to plot them
against?

Hadley


-- 
http://had.co.nz/



More information about the R-help mailing list