Graphing Mean PK profile [🇷 for BE/BA]

posted by Shuanghe  – Spain, 2019-04-23 20:31 (2023 d 20:55 ago) – Posting: # 20213
Views: 14,704

Dear roman_max,

❝ Can anyone share idea (R-code?) how to do it? How a data-set can be organized for this graph?


Assuming that your data file of individual concentration dat_ind contain at least the following variables: subj, treat, time, conc, you can get mean profile data with
library(dplyr)
dat_mean <- dat_ind %>%
  group_by(treat, time) %>%
  summarise(conc = mean(conc))


Obviously, time here should be the planned nominal time, not the actual sampling time. With ggplot you can have more or less what you asked for:

library(ggplot2)
p1 <- ggplot(data = dat_ind, aes(x = time, y = conc, color = treat)) +
  geom_point(aes(group = interaction(treat, time)), alpha = 0.5, shape = 1,
             position = position_jitter(width = 0.1, height = 0)) +
  geom_boxplot(aes(fill = treat, group = interaction(treat, time)), alpha = 0.3) +
  geom_line(data = dat_mean, size = 1.3)


The main idea is the group = interaction(treat, time). Feel free to modify the rest to better suit your needs (size/shape of the points etc). position_jitter() helps to avoid point overlapping (you have to specify height = 0 otherwise the data points will not reflect the true concentration value since some randomness will be introduced along y-axis by default) and the last line will add mean profiles with slightly bold lines.

All the best,
Shuanghe

Complete thread:

UA Flag
Activity
 Admin contact
23,288 posts in 4,890 threads, 1,658 registered users;
20 visitors (0 registered, 20 guests [including 10 identified bots]).
Forum time: 16:26 CET (Europe/Vienna)

‘Normal science’ means research firmly based upon one or more
past scientific achievements, achievements that some particular
scientific community acknowledges for a time as supplying
the foundation for its further practice.    Thomas S. Kuhn

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5