Setup

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
theo = read.csv("theoph.csv")

theo$Subject = factor(theo$Subject)

Project

str(theo)
## 'data.frame':    132 obs. of  5 variables:
##  $ Subject: Factor w/ 12 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ Wt     : num  79.6 79.6 79.6 79.6 79.6 79.6 79.6 79.6 79.6 79.6 ...
##  $ Dose   : num  4.02 4.02 4.02 4.02 4.02 4.02 4.02 4.02 4.02 4.02 ...
##  $ Time   : num  0 0.25 0.57 1.12 2.02 ...
##  $ conc   : num  0.74 2.84 6.57 10.5 9.66 8.58 8.36 7.47 6.89 5.94 ...
Subtheo = theo %>% select(Subject, Time, conc)

dosetheo = theo %>% select(Subject, Wt, Dose) %>% distinct(Subject, Wt, Dose)


sub1 = theo %>% filter(Subject == 1)

sub4 = theo %>% filter(Subject == 1 |Subject == 2|Subject == 3|Subject == 4)

theo %>% group_by(Subject) %>% summarise(mean(conc))
## # A tibble: 12 x 2
##    Subject `mean(conc)`
##  * <fct>          <dbl>
##  1 1               6.44
##  2 2               4.82
##  3 3               5.09
##  4 4               4.94
##  5 5               5.78
##  6 6               3.53
##  7 7               3.91
##  8 8               4.27
##  9 9               4.89
## 10 10              5.93
## 11 11              4.51
## 12 12              5.41
oneplot = sub1 %>% ggplot(aes(x = Time, y =conc)) + geom_line()

oneplot

Subtheo %>% ggplot(aes(x = Time, y =conc, group = Subject)) + geom_line(aes(color = Subject)) 

##This is where I messed up on the last assignment. I didn't realize aes/group existed, but that would have solved my problem on the last line plot.

Subtheo %>% ggplot(aes(x = Time, y =conc)) + geom_line(aes(color = Subject)) + facet_wrap(~Subject)