Skip to content

Commit

Permalink
Fixed example file (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
gowerc authored Feb 18, 2025
1 parent f055eae commit 016d639
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions design/examples/quantity_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ jlist <- SimJointData(
# random number of post baseline observations
dat_lm_bl <- jlist@longitudinal |>
filter(time <= 10 / 365) |>
group_by(pt) |>
group_by(subject) |>
sample_n(1) |>
ungroup()

dat_lm <- jlist@longitudinal |>
filter(time > 10 / 365, observed) |>
sample_frac(0.25) |>
bind_rows(dat_lm_bl) |>
arrange(pt, time)
arrange(subject, time)

dat_os <- jlist@survival |>
filter(pt %in% dat_lm$pt)
filter(subject %in% dat_lm$subject)



Expand Down Expand Up @@ -147,7 +147,7 @@ longquant_obvs <- LongitudinalQuantities(

dat_quant_obvs <- summary(longquant_obvs) |>
as_tibble() |>
left_join(dat_lm, by = c("group" = "pt", "time"))
left_join(dat_lm, by = c("group" = "subject", "time"))


ggplot(
Expand All @@ -168,7 +168,7 @@ ggplot(
#
#

sampled_subjects <- sample(dat_lm$pt, 4)
sampled_subjects <- sample(dat_lm$subject, 4)

longquant_fixed <- LongitudinalQuantities(
mp,
Expand All @@ -178,19 +178,22 @@ longquant_fixed <- LongitudinalQuantities(
)
)

# Note that autoplot just returns a regular ggplot2 object thus we can
# manipulate it in anyway that makes sense. The following shows how to change the labels
# and also how to get each pane to have their own "scale" (i.e. different xy-axis limits)
autoplot(longquant_fixed) +
ylab("Observed SLD (mm)") +
xlab("Time (years)")

xlab("Time (years)") +
facet_wrap(~group, scales = "free")

## Alternative if you want more customisation

dat_quant_fixed <- summary(longquant_fixed) |>
as_tibble()

dat_os_plot <- dat_os |>
mutate(group = pt) |>
filter(pt %in% sampled_subjects) |>
mutate(group = subject) |>
filter(subject %in% sampled_subjects) |>
mutate(event_chr = ifelse(event == 1, "Event", "Censored")) |>
mutate(event_chr = factor(
event_chr,
Expand All @@ -211,8 +214,8 @@ ggplot() +
col = "#81d681"
) +
geom_point(
data = dat_lm |> mutate(group = pt) |> filter(pt %in% sampled_subjects),
aes(x = time, y = sld, group = pt),
data = dat_lm |> mutate(group = subject) |> filter(subject %in% sampled_subjects),
aes(x = time, y = sld, group = subject),
col = "#9c3abf"
) +
geom_vline(
Expand Down Expand Up @@ -339,7 +342,7 @@ ggplot() +
) +
geom_line(
data = dat_lm,
aes(x = time, y = sld, group = pt),
aes(x = time, y = sld, group = subject),
alpha = 0.7,
size = 0.2
) +
Expand Down

0 comments on commit 016d639

Please sign in to comment.