[R] ggplot2 and facet

James Rome jamesrome at gmail.com
Tue Jun 7 22:01:42 CEST 2011


I have a data frame  (attached) that has interpolated EOT errors for
each minute before flight landing. It also has the runway and an index
for the flight:

> > times[1:4,]
  time       error runway flight
1    0 -0.02206235    04R      1
2    1 -0.07961631    04R      1
3    2 -0.13795380    04R      1
4    3 -0.20726073    04R      1

> > sapply(times, class)
     time     error    runway    flight
"numeric" "numeric"  "factor"  "factor"

I want to plot this using ggplot2
    library(ggplot2)
    pp2 = qplot(times$time, times$error, times)
    pp2 = pp2 + facet_wrap(~ times$runway)
    print(pp2)
But when I try it, I get the error
Error in fix.by(by.x, x) : 'by' must specify valid column(s)
I get the same error if I make times$time a factor:

> > times$time = as.factor(times$time)
> > sapply(times, class)
     time     error    runway    flight
 "factor" "numeric"  "factor"  "factor"

> >     pp2 = qplot(times$time, times$error, times)
> >     pp2 = pp2 + facet_wrap(~ times$runway)
> >     print(pp2)
Error in fix.by(by.x, x) : 'by' must specify valid column(s)

What am I doing wrong?

And I really want to make a boxplot for every minute of times$time, but
when I try that, I get one single box.

Thanks for the help,
Jim



More information about the R-help mailing list