Visualizing prescription drugs using a Dumbbell chart in R


In this post, I am going to show you how to visualize prescription periods of drugs using a Dumbbell chart in R.

library(ggalt)  # For Dumbbel charts

Here I am going to use the prescriptions table from MIMIC-III Clinical Database Demo. I will extract prescription records for a single patient.

df <- read_csv("path/to/PRESCRIPTIONS.csv")
df$startdate <- as.Date(df$startdate)
df$enddate <- as.Date(df$enddate)

df_single_patient <- df %>% 
  filter(subject_id == 40456) %>% 
  select(subject_id, startdate, enddate, drug) %>% 
  mutate(start_day = startdate - min(startdate), 
         end_day = enddate - min(startdate))

Specify the order of drugs depending on the prescription start date.

drug_order <- df_single_patient %>% 
  arrange(startdate) %>% 
  pull(drug) %>% 

df_single_patient$drug <- factor(df_single_patient$drug, levels = drug_order)

Now let’s plot it.

ggplot(df_single_patient, aes(y = drug, x = start_day, xend = end_day)) + 
  ggalt::geom_dumbbell(size = 1, 
                       size_x = 2, 
                       size_xend = 2, 
                       colour = "grey60", 
                       colour_x = "red", 
                       colour_xend = "red") + 
  theme_minimal() + 
  labs(title = "Prescription information", 
       x = "Follow-up duration (days)", 
       y = "Drug")


Data Visualization with R
A guide to creating modern data visualizations with R. Starting with data preparation, topics include how to create effective univariate, bivariate, and multiva...


Copied title and URL