Skip to content

Instantly share code, notes, and snippets.

@solmos
Created April 14, 2021 07:48
Show Gist options
  • Save solmos/456da8f036196432b5d2aee5b75da81c to your computer and use it in GitHub Desktop.
Save solmos/456da8f036196432b5d2aee5b75da81c to your computer and use it in GitHub Desktop.
library(tidyverse)
## Simple example dataset
time_on_study <- tibble(
id = 1:5,
start_followup = 0,
time_followup = c(2, 4, 3, 1, 3),
age_baseline = c(18, 30, 28, 20, 18),
event = factor(c(1, 0, 1, 1, 0), labels = c("Censored", "Event"))
)
## Without age
ggplot(time_on_study) +
geom_point(aes(start_followup, id),
size = 3, shape = 15) +
geom_point(aes(time_followup, id, shape = event),
size = 3) +
geom_segment(aes(start_followup, id,
xend = time_followup, yend = id)) +
labs(
title = "Time-on-study example",
x = "Years since start of follow-up",
y = "Subject"
) +
theme_minimal()
## With age as color
ggplot(time_on_study) +
geom_point(aes(start_followup, id, color = age_baseline),
size = 3, shape = 15) +
geom_point(aes(time_followup, id, shape = event, color = age_baseline),
size = 3) +
geom_segment(aes(start_followup, id,
xend = time_followup, yend = id,
color = age_baseline)) +
labs(
title = "Time-on-study example",
x = "Years since start of follow-up",
y = "Subject"
) +
theme_minimal()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment