Skip to content

g_lineplot function - connect non-continuous points #149

@wwojciech

Description

@wwojciech

Original message

g_lineplot does not connect points for non-continuous data points.

Screenshot 2021-09-22 at 09 39 45

Example to reproduce

adlb <- scda::synthetic_cdisc_data("latest")$adlb
adlb <- dplyr::filter(
  adlb, 
  ANL01FL == "Y", 
  PARAMCD == "ALT", 
  AVISIT != "SCREENING",
  !(ARM == "A: Drug X" & AVISIT == "WEEK 2 DAY 15")
) %>%
droplevels()

g_lineplot(adlb, subtitle = "Laboratory Test: ALT")

It would be great to assess whether g_lineplot could be extended so that such non-continuous points are connected.
See also MNG01 in STREAM, where non-continuous data points are connected.

TODO

Use Xiaoying's example code, and connect non-continious points, see below
#149 (comment)

library(ggplot2)

set.seed(4321)

df = data.frame(
  mean = ifelse(rbinom(10, 1, 0.8) == 1, runif(10, 0, 15), NA),
  upper = ifelse(rbinom(10, 1, 0.8) == 1, runif(10, 15, 20), NA),
  lower = ifelse(rbinom(10, 1, 0.8) == 1, runif(10, -5, 0), NA),
  ARM = rep(c('A', 'B'), each = 5), 
  VISIT = rep(1:5, 2)
) 

pd = position_dodge(0.8)

df %>% 
  filter(!is.na(mean)) %>% 
  mutate(upper = ifelse(is.na(lower), NA, upper),
         lower = ifelse(is.na(upper), NA, lower)) %>% 
  ggplot(aes(VISIT, mean, color = ARM)) +
  theme_bw() +
  geom_point(position = pd) +
  geom_line(position = pd) + 
  geom_errorbar(aes(ymin = lower, ymax = upper), position = pd) 

image

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions