insightsengineering / tern

Table, Listings, and Graphs (TLG) library for common outputs used in clinical trials
https://insightsengineering.github.io/tern/
Other
77 stars 21 forks source link

examples - wrong proportions for g_lineplot with tables - seen in pkgdown #399

Closed Polkas closed 2 years ago

Polkas commented 2 years ago

Does it a general problem of this function or even all (plot + table) functions?

The g_lineplot graphs with tables look very bad because of wrong proportions, on pkgdown website.

image

Source: https://bookish-invention-97673167.pages.github.io/reference/g_lineplot.html

kpagacz commented 2 years ago

I don't think the proportions are wrong. It's just the viewport to which the plot is rendered is too small to correctly display everything without overlap.

You can reproduce this by running the example and playing with the window that R tries to fit the plot to. E.g.:

adsl <- scda::synthetic_cdisc_data("latest")$adsl
adlb <- scda::synthetic_cdisc_data("latest")$adlb
adlb <- dplyr::filter(adlb, ANL01FL == "Y", PARAMCD == "ALT", AVISIT != "SCREENING")
adlb$AVISIT <- droplevels(adlb$AVISIT)
adlb <- dplyr::mutate(adlb, AVISIT = forcats::fct_reorder(AVISIT, AVISITN, min))
# Mean with CI plot with stats table
tern::g_lineplot(adlb, adsl, table = c("n", "mean", "mean_ci"))

And by changing the size of the window: image

image

I am unsure about how to proceed.

I don't think putting some strict pixel requirements is a particularly good idea - better to rely on grid and ggplot2 to do its thing.

Ideally, I would find a way to increase the size of the plot in pkgdown to accommodate the inherent requirement of the plot but my research so far didn't yield a way to do it. Maybe I am looking in the wrong places :(

kpagacz commented 2 years ago

Unassigning because I don't agree with the solutions I have come up with and didn't find a way to do it otherwise.