R에 기본적으로 내장된 Indometh (Indomethacin IV bolus 시의 PK) 의 concentration-time curve를 ggplot2와 Hmisc 패키지를 사용해 각각 그려보겠습니다.
먼저 ggplot2를 사용해 그림을 그려보면 다음과 같습니다.
library(ggplot2)
head(Indometh)
## Subject time conc
## 1 1 0.25 1.50
## 2 1 0.50 0.94
## 3 1 0.75 0.78
## 4 1 1.00 0.48
## 5 1 1.25 0.37
## 6 1 2.00 0.19
ggplot(Indometh, aes(x=time, y=conc, col = Subject)) +
geom_line() +
geom_point()
stat_summary 함수를 사용하여 손쉽게 계산할 수 있습니다.ggplot(Indometh, aes(x=time, y=conc)) +
stat_summary(fun.y=mean, geom=c("line"), size=0.3) +
stat_summary(fun.y=mean, geom=c("point"), size=2) +
stat_summary(fun.data = "mean_cl_boot", geom = "errorbar", col = "red", width = 0.3)
library(dplyr)
# Data Prep for Mean and SD
Indometh2 <- Indometh %>%
group_by(time) %>%
summarise(Concentration = mean(conc), StandardDev = sd(conc))
Indometh2
## # A tibble: 11 x 3
## time Concentration StandardDev
## <dbl> <dbl> <dbl>
## 1 0.25 2.07666667 0.41355370
## 2 0.50 1.32166667 0.27095510
## 3 0.75 0.91833333 0.17634247
## 4 1.00 0.68333333 0.20422210
## 5 1.25 0.55666667 0.18704723
## 6 2.00 0.33166667 0.09703951
## 7 3.00 0.19833333 0.07652886
## 8 4.00 0.13666667 0.03881580
## 9 5.00 0.12500000 0.06410928
## 10 6.00 0.09000000 0.02000000
## 11 8.00 0.07166667 0.01471960
# Drawing
with(Indometh2,
Hmisc::errbar(x = time,
y = Concentration,
yplus = Concentration+StandardDev,
yminus = Concentration-StandardDev,
col ="red", type = "b"))