Creates a ggplot time-profile plot from longitudinal data with optional summarization (mean/median/geometric mean), variance bands (SD/SE/IQR), percentile ribbons, faceting, and log scaling.
Usage
sg_sim_tp(
ds_i,
time_col = "TIME",
val_col = "VALUE",
group_i = "VAR",
bands_i = NULL,
cent_i = NULL,
vrns_i = NULL,
lperc_i = NULL,
uperc_i = NULL,
add_points = 0,
col_i = NULL,
fill_i = NULL,
lty_i = NULL,
shp_i = NULL,
grid_i = NULL,
wrap_i = NULL,
free_stat = "free",
wrap_ncol = NULL,
wrap_nrow = NULL,
min_x = NA,
max_x = NA,
min_y = NA,
max_y = NA,
log_y = FALSE,
log_x = FALSE
)Arguments
- ds_i
Data.frame. The data frame with source data.
- time_col
String. The column to use as a time column. Currently, can be only
TIME. Default isTIME.- val_col
String. Name of value column. Default is
VALUE.- group_i
String. Primary grouping variable for lines. Default is
'VAR'.- bands_i
vector of characters. Character vector of length 2 with column names for custom ymin/ymax ribbons. Default is
NULL- cent_i
string. Central tendency measure. One of
'mean','median','geom_mean', orNULLfor raw values. Default isNULL- vrns_i
string. Variance band type. One of
'SD','SE','IQR', orNULL. Default isNULL- lperc_i
numeric. Lower percentile for percentile ribbons (must be provided together with
uperc_i). Default isNULL- uperc_i
numeric. Upper percentile for percentile ribbons (must be provided together with
lperc_i). Default isNULL- add_points
numeric. Size of points to add to the plot. If > 0, points will be added. Default is
0- col_i
String. Column name for color
- fill_i
String. Column name for fill aesthetic. Default is
NULL- lty_i
String. Column name for linetype aesthetic. Default is
NULL.- shp_i
String. Column name for shape aesthetic. Default is
NULL.- grid_i
string. Faceting formula for
facet_grid(e.g.,'~VAR'or'A~B'). Default isNULL- wrap_i
String. Faceting formula for
facet_wrap. Default isNULL.- free_stat
String. Facet scaling option. One of
"free","free_x","free_y", or"fixed". Default is'free'.- wrap_ncol
Integer. Number of columns for
facet_wrap. Default isNULL.- wrap_nrow
Integer. Number of rows for
facet_wrap. Default isNULL.- min_x
Numeric. X-axis minimum limit. Default is
NA.- max_x
Numeric. X-axis maximum limit. Default is
NA.- min_y
Numeric. Y-axis minimum limit. Default is
NA.- max_y
Numeric. Y-axis maximum limit. Default is
NA.- log_y
Logical. If
TRUE, a logarithmic scale is applied to y-axis. Default isFALSE.- log_x
Logical. If
TRUE, a logarithmic scale is applied to x-axis. Default isFALSE.
Examples
make_extended_mock_data <- function() {
data.frame(
TIME = rep(1:4, times = 6),
VALUE = rnorm(24, mean = 10, sd = 2),
VAR = rep(rep(c("A", "B"), each = 4), times = 3),
Regimen = rep(c("R1", "R2", "R3"), each = 8),
CAT1 = rep(c("Cat1", "Cat2"), each = 12)
)
}
ds_sim <- make_extended_mock_data()
p <- sg_sim_tp(ds_i = ds_sim, group_i = 'VAR', col_i = 'VAR', fill_i = 'VAR',
wrap_i = '~VAR', wrap_ncol = 2)
#> Error: cannot open file '/tmp/RtmpLedq7K/temp_libpath8b6abff614d/SimuRg/R/SimuRg.rdb': No such file or directory
p
#> Error: object 'p' not found
