Usage
g_lineplot(
  df,
  alt_counts_df = NULL,
  variables = control_lineplot_vars(),
  mid = "mean",
  interval = "mean_ci",
  whiskers = c("mean_ci_lwr", "mean_ci_upr"),
  table = NULL,
  sfun = tern::s_summary,
  ...,
  mid_type = "pl",
  mid_point_size = 2,
  position = ggplot2::position_dodge(width = 0.4),
  legend_title = NULL,
  legend_position = "bottom",
  ggtheme = nestcolor::theme_nest(),
  x_lab = obj_label(df[[variables[["x"]]]]),
  y_lab = NULL,
  y_lab_add_paramcd = TRUE,
  y_lab_add_unit = TRUE,
  title = "Plot of Mean and 95% Confidence Limits by Visit",
  subtitle = "",
  subtitle_add_paramcd = TRUE,
  subtitle_add_unit = TRUE,
  caption = NULL,
  table_format = summary_formats(),
  table_labels = summary_labels(),
  table_font_size = 3,
  newpage = TRUE,
  col = NULL
)Arguments
- df
- ( - data.frame)
 data set containing all analysis variables.
- alt_counts_df
- ( - data.frameor- NULL)
 data set that will be used (only) to counts objects in groups for stratification.
- variables
- 
(named charactervector) of variable names indfdata set. Details are:- x(- character)
 name of x-axis variable.
- y(- character)
 name of y-axis variable.
- group_var(- character)
 name of grouping variable (or strata), i.e. treatment arm. Can be- NAto indicate lack of groups.
- subject_var(- character)
 name of subject variable. Only applies if- group_varis not NULL.
- paramcd(- character)
 name of the variable for parameter's code. Used for y-axis label and plot's subtitle. Can be- NAif- paramcdis not to be added to the y-axis label or subtitle.
- y_unit(- character)
 name of variable with units of- y. Used for y-axis label and plot's subtitle. Can be- NAif y unit is not to be added to the y-axis label or subtitle.
 
- mid
- ( - characteror- NULL)
 names of the statistics that will be plotted as midpoints. All the statistics indicated in- midvariable must be present in the object returned by- sfun, and be of a- doubleor- numerictype vector of length one.
- interval
- ( - characteror- NULL)
 names of the statistics that will be plotted as intervals. All the statistics indicated in- intervalvariable must be present in the object returned by- sfun, and be of a- doubleor- numerictype vector of length two. Set- interval = NULLif intervals should not be added to the plot.
- whiskers
- ( - character)
 names of the interval whiskers that will be plotted. Names must match names of the list element- intervalthat will be returned by- sfun(e.g.- mean_ci_lwrelement of- sfun(x)[["mean_ci"]]). It is possible to specify one whisker only, or to suppress all whiskers by setting- interval = NULL.
- table
- ( - characteror- NULL)
 names of the statistics that will be displayed in the table below the plot. All the statistics indicated in- tablevariable must be present in the object returned by- sfun.
- sfun
- ( - closure)
 the function to compute the values of required statistics. It must return a named- listwith atomic vectors. The names of the- listelements refer to the names of the statistics and are used by- mid,- interval,- table. It must be able to accept as input a vector with data for which statistics are computed.
- ...
- optional arguments to - sfun.
- mid_type
- ( - character)
 controls the type of the- midplot, it can be point (- p), line (- l), or point and line (- pl).
- mid_point_size
- ( - integeror- double)
 controls the font size of the point for- midplot.
- position
- ( - characteror- call)
 geom element position adjustment, either as a string, or the result of a call to a position adjustment function.
- legend_title
- ( - characterstring)
 legend title.
- legend_position
- ( - character)
 the position of the plot legend (- none,- left,- right,- bottom,- top, or two-element numeric vector).
- ggtheme
- ( - theme)
 a graphical theme as provided by- ggplot2to control styling of the plot.
- x_lab
- ( - character)
 x-axis label. If equal to- NULL, then no label will be added.
- y_lab
- ( - character)
 y-axis label. If equal to- NULL, then no label will be added.
- y_lab_add_paramcd
- ( - logical)
 should- paramcd, i.e.- unique(df[[variables["paramcd"]]])be added to the y-axis label- y_lab?
- y_lab_add_unit
- ( - logical)
 should y unit, i.e.- unique(df[[variables["y_unit"]]])be added to the y-axis label- y_lab?
- title
- ( - character)
 plot title.
- subtitle
- ( - character)
 plot subtitle.
- subtitle_add_paramcd
- ( - logical)
 should- paramcd, i.e.- unique(df[[variables["paramcd"]]])be added to the plot's subtitle- subtitle?
- subtitle_add_unit
- ( - logical)
 should y unit, i.e.- unique(df[[variables["y_unit"]]])be added to the plot's subtitle- subtitle?
- caption
- ( - character)
 optional caption below the plot.
- table_format
- (named - characteror- NULL)
 format patterns for descriptive statistics used in the (optional) table appended to the plot. It is passed directly to the- h_format_rowfunction through the- formatparameter. Names of- table_formatmust match the names of statistics returned by- sfunfunction.
- table_labels
- (named - characteror- NULL)
 labels for descriptive statistics used in the (optional) table appended to the plot. Names of- table_labelsmust match the names of statistics returned by- sfunfunction.
- table_font_size
- ( - integeror- double)
 controls the font size of values in the table.
- newpage
- ( - logical)
 should plot be drawn on new page?
- col
- ( - character)
 colors.
Examples
library(nestcolor)
adsl <- tern_ex_adsl
adlb <- tern_ex_adlb %>% dplyr::filter(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
g_lineplot(adlb, adsl, subtitle = "Laboratory Test:")
 # Mean with CI, no stratification with group_var
g_lineplot(adlb, variables = control_lineplot_vars(group_var = NA))
# Mean with CI, no stratification with group_var
g_lineplot(adlb, variables = control_lineplot_vars(group_var = NA))
 # Mean, upper whisker of CI, no group_var(strata) counts N
g_lineplot(
  adlb,
  whiskers = "mean_ci_upr",
  title = "Plot of Mean and Upper 95% Confidence Limit by Visit"
)
# Mean, upper whisker of CI, no group_var(strata) counts N
g_lineplot(
  adlb,
  whiskers = "mean_ci_upr",
  title = "Plot of Mean and Upper 95% Confidence Limit by Visit"
)
 # Median with CI
g_lineplot(
  adlb,
  adsl,
  mid = "median",
  interval = "median_ci",
  whiskers = c("median_ci_lwr", "median_ci_upr"),
  title = "Plot of Median and 95% Confidence Limits by Visit"
)
# Median with CI
g_lineplot(
  adlb,
  adsl,
  mid = "median",
  interval = "median_ci",
  whiskers = c("median_ci_lwr", "median_ci_upr"),
  title = "Plot of Median and 95% Confidence Limits by Visit"
)
 # Mean, +/- SD
g_lineplot(adlb, adsl,
  interval = "mean_sdi",
  whiskers = c("mean_sdi_lwr", "mean_sdi_upr"),
  title = "Plot of Median +/- SD by Visit"
)
# Mean, +/- SD
g_lineplot(adlb, adsl,
  interval = "mean_sdi",
  whiskers = c("mean_sdi_lwr", "mean_sdi_upr"),
  title = "Plot of Median +/- SD by Visit"
)
 # Mean with CI plot with stats table
g_lineplot(adlb, adsl, table = c("n", "mean", "mean_ci"))
# Mean with CI plot with stats table
g_lineplot(adlb, adsl, table = c("n", "mean", "mean_ci"))
 # Mean with CI, table and customized confidence level
g_lineplot(
  adlb,
  adsl,
  table = c("n", "mean", "mean_ci"),
  control = control_analyze_vars(conf_level = 0.80),
  title = "Plot of Mean and 80% Confidence Limits by Visit"
)
# Mean with CI, table and customized confidence level
g_lineplot(
  adlb,
  adsl,
  table = c("n", "mean", "mean_ci"),
  control = control_analyze_vars(conf_level = 0.80),
  title = "Plot of Mean and 80% Confidence Limits by Visit"
)
 # Mean with CI, table, filtered data
adlb_f <- dplyr::filter(adlb, ARMCD != "ARM A" | AVISIT == "BASELINE")
g_lineplot(adlb_f, table = c("n", "mean"))
# Mean with CI, table, filtered data
adlb_f <- dplyr::filter(adlb, ARMCD != "ARM A" | AVISIT == "BASELINE")
g_lineplot(adlb_f, table = c("n", "mean"))
 
