0

I'm trying to plot observed and predicted variables on the same plot in lattice. My data is a repeated dataset and I've tried a few things which haven't worked. Any assistance would be much appreciated. Code is given below.

library(nlme)
library(lattice)
# add random conc predictions to data
Theoph$predConc <- rnorm(132, 5)

# My attempt at plotting both predConc and conc against time on the same plot
lattice::xyplot(predConc + conc ~ Time | Subject, groups=Subject, data=Theoph, type="l", layout = c(4,4))

As you can see, it doesn't seem to be doing what I want it to do. Ideally I would like the "conc" and "predConc" to be in different colours but appear together on each panel for each Id so I can compare the two easily.

John_dydx
  • 951
  • 1
  • 14
  • 27
  • 1
    You use "Subject" twice in `xyplot`. Try `xyplot(predConc + conc ~ Time | Subject, data = Theoph, t='l')`. –  May 15 '15 at 07:51
  • @Pascal, thanks for that. Didn't think it was so simple. Cheers! – John_dydx May 15 '15 at 07:56

1 Answers1

1

As was suggested in the comments, it is fixed simply by dropping groups = Subject.

lattice::xyplot(predConc + conc ~ Time | Subject, data = Theoph, type = "l",
                auto.key = TRUE)

Imgur

Johan Larsson
  • 3,496
  • 18
  • 34