Help! Your colleague Jon has come to you for help. He is just starting to use ggplot and is having trouble. Thankfully, he has gotten started on making the necessary plots, and has a good idea what he wants. Your job, should you choose to accept it, is to help finish off the plots Jon has started.

Jon has been kind enough to provide you with a zipped R project. You can unzip the project and click on the .Rproj to open up the project to get you started.

libraries <- c("dplyr",
               "ggplot2",
               "knitr",
               "PKPDdatasets",
               "PKPDmisc"
               )
suppressMessages(sapply(libraries, require, character.only=T))
##        dplyr      ggplot2        knitr PKPDdatasets     PKPDmisc 
##         TRUE         TRUE         TRUE         TRUE         TRUE
opts_chunk$set(cache=T, fig.width=9)

The data Jon is working with conventiently comes from the dapa_iv_oral dataset in the PKPDdatasets package.

Jon’s first attempt to make a concentration time plot for each ID looks funny.

oral_data <- dapa_IV_oral %>% filter(FORMULATION == "ORAL")
head(oral_data)
##   ID   TIME  TAD    COBS AMT_IV AMT_ORAL OCC AGE WEIGHT GENDER FORMULATION
## 1  1 168.00 0.00  0.0000      0     5000   2  44   70.5      0        ORAL
## 2  1 168.05 0.05 13.7152      0        0   2  44   70.5      0        ORAL
## 3  1 168.35 0.35 62.3357      0        0   2  44   70.5      0        ORAL
## 4  1 168.50 0.50 67.9444      0        0   2  44   70.5      0        ORAL
## 5  1 168.75 0.75 66.3308      0        0   2  44   70.5      0        ORAL
## 6  1 169.00 1.00 86.3231      0        0   2  44   70.5      0        ORAL
ggplot(oral_data, aes(x = TAD, y = COBS, group = ID, color = OCC)) + geom_line() + 
  facet_wrap(~ID)

You will need to help him adjust:

to get a final plot that looks like this: