#Install package (only the first time)
install.packages(c("tidyverse", "ggpmisc", "gtsummary", "medicaldata"))Publication Ready Graphs and Tables in R
Note that this workshops assumes a working knowledge of R; we will dive straight into main graph and content without a general overview of R.
Install and load packages
This workshop will use the packages tidyverse (for data manipulation and plotting; this includes the ggplot2 package), ggpmisc (for adding statistical annotations to plots), gtsummary (for table formatting) and medicaldata for example datasets.
About the data
This session will use the smartpill dataset from the medicaldata package.
attach(smartpill)
data(smartpill)Data description: This study evaluated gastric emptying, small bowel transit time, and total intestinal transit time in 8 critically ill trauma patients. These data were compared with those obtained in 87 healthy volunteers from a separate trial. Data were obtained with a motility capsule that wirelessly transmitted pH, pressure, and temperature to a recorder attached to each subject’s abdomen. Transit times were available for almost all patients, however, pH, pressure and temperature data is missing for all critically ill patients and sparsely missing for the healthy volunteers.
Group= Study group, numeric, 0 = Critically Ill Trauma Patient, 1 = Healthy VolunteerGender= Gender, numeric, range: 0 = Female, 1 = MaleRace= Race, numeric, 1 = White, 2 = Black, 3 = Asian/Pacific Islander, 4 = Hispanic, 5 = OtherHeight= Height (centimeters), numeric, range: 132.1-193.0Weight= Weight (kilograms), numeric, range: 44.9-127.0Age= Age (years), numeric, range: 18.0-72.0GE.Time= Gastric Emptying Time is time from ingestion to gastric emptying (hours), numeric, range: 1.7-74.3SB.Time= Small Bowel Transit Time is time from gastric emptying to ileocecal junction (hours), numeric, range: 1.8-13.8C.Time= Colonic Transit Time is time from ileocecal junction to body exit (hours), numeric, range: 0.7-118.9WG.Time= Whole Gut Time is time from ingestion to body exit (hours), numeric, range: 6.0-816.0S.Contractions= Stomach contractions are counted if the peak amplitude of the contraction is over 10 mmHg and under 300 mmHg, numeric, range: 47.0-1665.0S.Sum.of.Amplitudes= Stomach sum of amplitudes (mm Hg), numeric, range: 655.6-33800.3S.Mean.Peak.Amplitude= Stomach mean peak amplitude is the sum of amplitudes divided by number of contractions (mm Hg), numeric, range: 4.6-43.4S.Mean.pH= Stomach mean pH is the average pH over the whole recording time in the stomach with normal ~ 1.5-3.5, numeric, range: 1.5-5.9SB.Contractions= Small Bowel contractions are counted if the peak amplitude of the contraction is over 10 mmHg and under 300 mmHg, numeric, range: 223.0-2375.0SB.Sum.of.Amplitudes= Small Bowel sum of amplitudes (mm Hg), numeric, range:3899.4-41122.5SB.Mean.Peak.Amplitude= Small Bowell mean peak amplitude is the sum of amplitudes divided by number of contractions (mm Hg), numeric, range: 15.0-27.9SB.Mean.pH= Small Bowel mean pH is the average pH over the whole recording time in the small bowel, normal ~ 6-7.4, numeric, range: 4.7-8.6Colon.Contractions= Colon contractions are counted if the peak amplitude of the contraction is over 10 mmHg and under 300 mmHg, numeric, range: 41.0-2672.0Colon.Sum.of.Amplitudes= Colon sum of amplitudes (mm Hg), numeric, range:1872.6-117707.5C.Mean.Peak.Amplitude= Colon mean peak amplitude is the sum of amplitudes divided by number of contractions (mm Hg), numeric, range: 32.8- 64.2C.Mean.pH= Colon mean pH is the average pH over the whole recording time in the colon, normal ~ 5-7-6.7, numeric, range: 3.9-8.1
The Smart Pill dataset was contributed by Dr. Amy Nowacki, Associate Professor, Cleveland Clinic. Please refer to this resource as: Amy S. Nowacki, ‘Smart Pill Dataset’, TSHS Resources Portal (2017). Available at https://www.causeweb.org/tshs/smart-pill/.
Portions of this content are derived from the UC Love Data Week 2026 workshop Publication Ready Tables in R developed by Stephanie Labou and Julien Brun.