I am trying to create lattice xyplot with multiple panels using the code below. The problem is that it is adding all median lines on all panels (i.e ablines are not grouped by Subject). Is there a way to subset median lines per subject?
Below is a reproducible example using Theoph dataset from PKPDdatasets package.
# devtools::install_github("dpastoor/PKPDdatasets")
library(PKPDdatasets)
library(lattice)
library(latticeExtra)
library(dplyr)
Theoph_Data <- Theoph
Theoph_Data1 <- Theoph_Data %>% group_by(Subject) %>% mutate(Median= median(Time))
print(Theoph_Data1)
Theoph_PK <- xyplot(conc ~ Time| Subject, data=Theoph_Data1,
panel = function(x,y,...) {
panel.xyplot(x,y,...)
panel.abline(v=Theoph_Data1$Median)
})
Theoph_PK