myModel <- inlineModel("
  [LONGITUDINAL]
input = {ka, V, Cl}
EQUATION:
C = pkmodel(ka,V,Cl)

[INDIVIDUAL]
input = {ka_pop, V_pop, Cl_pop, omega_ka, omega_V, omega_Cl}
DEFINITION:
ka = {distribution=lognormal, reference=ka_pop, sd=omega_ka}
V  = {distribution=lognormal, reference=V_pop,  sd=omega_V }
Cl = {distribution=lognormal, reference=Cl_pop, sd=omega_Cl}
")

Ng=400

pop.param   <- c(
  ka_pop  = 1,    omega_ka  = 0.5,
  V_pop   = 10,   omega_V   = 0.4,
  Cl_pop  = 1,    omega_Cl  = 0.3)

We define 4 treatment groups:

g1 <- list(size=Ng, level='individual', treatment = list(time=0, amount=60))
g2 <- list(size=Ng, level='individual', treatment = list(time=0, amount=100))
g3 <- list(size=Ng, level='individual', treatment = list(time=3, amount=60))
g4 <- list(size=Ng, level='individual', treatment = list(time=3, amount=100))

t.out <- seq(0,24,by=0.5)
res <- simulx(model     = myModel,
              parameter = pop.param,
              group     = list(g1, g2, g3, g4),
              output    = list(name='C', time=t.out))

By default, column “group” is used - if it exists - to make subplot

labels <- c("60 mg - 0h ", "100 mg - 0h", "60 mg - 3h ", "100 mg - 3h")
resC <- res$C
prctilemlx(resC, label=labels) + theme(legend.position = "none")

facet_wrap is used by prctilemlx with the default settings to produce these subplots. These default settings can be modified using facet_wrap explicitely

prctilemlx(resC, label=labels) + theme(legend.position = "none")  + facet_wrap(~ group, nrow=1)

A single plot is produced with group=“none” as input argument

prctilemlx(resC, group="none") 

Covariates, such as the time of dose, or the dose amount can be added to the data frame resC and used as categorical covariates to define groups.

resC$doseTime <- 0
resC$doseTime[res$C$group %in% c(3,4)] <- 3
resC$doseAmount <- 60
resC$doseAmount[res$C$group %in% c(2,4)] <- 100

These covariates can now be used separately as factors to make subplots

prctilemlx(resC, group="doseAmount", labels=c("60 mg", "100 mg"))   + theme(legend.position = "none") 

prctilemlx(resC, group="doseTime", labels=c("0 h", "3 h"))  + 
  theme(legend.position = "none") 

or for plotting the different predictive distributions on a same plot using facet=FALSE

prctilemlx(resC, group="doseTime", facet=FALSE)  + theme(legend.position = "none") 

These covariates can also be combined to make a panel of subplots

prctilemlx(resC, group=c("doseTime", "doseAmount"), labels=list(c("0 h", "3 h"),c("60 mg", "100 mg"))) + theme(legend.position = "none") 

Default settings of facet_grid which are used can be modified

prctilemlx(resC, group=c("doseTime", "doseAmount"), labels=list(c("0 h", "3 h"),c("60 mg", "100 mg"))) +
  facet_grid(doseAmount~doseTime) + theme(legend.position = "none") 

It is also possible to use a data.frame of (categorical) covariates for group. This data frame should have a column id and one or two columns of covariates used for making the subplots.

Example with one covariate:

N <- nlevels(res$C$id)
dose.time <- rep(c(0,3),each=N/2)
cov <- data.frame(id=levels(res$C$id), doseTime=dose.time)
head(cov)
##   id doseTime
## 1  1        0
## 2  2        0
## 3  3        0
## 4  4        0
## 5  5        0
## 6  6        0
prctilemlx(res$C, group=cov[c("id","doseTime")], labels=c("0 h", "3 h")) + theme(legend.position = "none")