Comparing Exposures with back to back Density/Boxplots
pediatrics
visualization
Author
Samer Mouksassi
Published
October 16, 2025
In this post, I will cover visualizing simulated drug exposures head to head compare using some ggplot2 tricks. First we use the NHANES body weight (kg), illustrate the effects of taking into account survey weights in the quantile regression showing the 5th, 50th, and 95th percentiles. I also overlay the simulated demographics (red points).
Code
library(ggplot2)library(tidyr)library(dplyr)library(patchwork)library(nhanesgamlss)library(gganimate)factor.with.units <-function(x, units) { l <-sort(unique(x)) y <-factor(x, levels=l, labels=paste(l, units))}# note https://cran.r-project.org/web/packages/RNHANES/vignettes/introduction.html# RNHANES help in applying survey weights and in downloading NHANES data# I am using a bmxdata.csv# bmxdata <- nhanes_load_data("BMX", "2013-2014", cache = "./nhanes_data",# demographics = TRUE,recode = TRUE)bmxdata <-read.csv("bmxdata.csv")pedcov4000 <-read.csv("pedcov4000.csv") %>%filter(AGEY<=18) %>%mutate(RIAGENDR =ifelse(SEX=="boys","Male","Female"))ggplot(bmxdata %>%filter(RIDAGEYR<=18),aes(RIDAGEYR,BMXWT))+geom_point(aes(alpha=WTMEC2YR/1000) )+geom_quantile(method ="rqss",quantiles =c(0.05,0.5,0.95),lambda=10,aes(weight = WTMEC2YR,col="rqss-weighted"),linewidth=1.5, alpha =0.6)+geom_quantile(method ="rqss",quantiles =c(0.05,0.5,0.95),lambda=10,aes(col="rqss"),linewidth=1.5, alpha =0.6)+geom_point(data = pedcov4000,aes(x=AGEY,y = WT),col="red",alpha=0.1)+facet_grid(~RIAGENDR)+labs(x="Years", y ="Weight (kg)",color="quantile regression",alpha="NHANES Weights")+scale_color_manual(values=c("#093B6D", "#EF761B"))+theme_bw()+theme(strip.placement ="outside",strip.text.y.left =element_text(angle=0),strip.background = ggplot2::element_rect(fill ="#475c6b"), strip.text = ggplot2::element_text(face ="bold", color ="white"))
I then plug these demographics into an mrgsolve model and simulate flat fixed dose of 150 mg versus a 2 mg/kg dose ( 150 mg for a 75 kg individual). The resulting areas under the curves (AUC’s) are compared using boxplots.
Ideally we want to keep what we compare close together i.e. the fixed Dose exposures next to the perKg Dose as shown in the second plot above. As a pharmacometrician, I like to see the distribution not just the boxplot so I come up with a hybrid density/boxplot visual below which I will call the back to back density boxplot.
We see that the fixed dosing has the densities crossing above the therapeutic range [0.25-1.5] mg*h/mL.
Next, we simulate two fixed dosing strategy reducing the fixed doses by a percentage:
Dose Strategy b: dose reduced by 80%, 50% and 40 % for the (45,60], (30,45], and (15,30] kg, respectively.
Dose Strategy c: dose reduced by 75%, 50% and 30 % for the (45,60], (30,45], and (15,30] kg, respectively.