Description Usage Arguments Details Value Author(s) Examples
Creats time-profiling plots with longitudinal data
1 2 3 4 5 6 7 8 9 10 11 12 13 | gg_time_profiling(data, x, y, subject = NULL, group = NULL,
group_levels = NULL, facet_r = NULL, facet_c = NULL,
facet_r_levels = NULL, facet_c_levels = NULL, facet_scale = "free",
facet_space = "fixed", x_lab = x, y_lab = y, group_lab = group,
title = "", x_limit = NULL, y_limit = NULL, x_tick_label = x,
all_xticks = FALSE, x_tick_angle = 0, y_tick_angle = 0,
geoms = c("point", "line", "sumline", "boxplot"), avg_method = "mean",
var_method = "se", y_log = FALSE, sample_size = TRUE,
sample_size_font_size = 3, reference_hline = NULL,
reference_vline = NULL, subject_show = FALSE, subject_label_size = 0.8,
add_legend = TRUE, legend_pos = "bottom", all_colors = NULL,
all_linetypes = NULL, jitter_factor = 1, grids = "on",
bw_theme = TRUE, randseed = NULL, return_data = FALSE)
|
data |
Data frame: default dataset to use for plot |
x |
Character: name of a |
y |
Character: name of a |
subject |
Character: name of a |
group |
Character: name of a |
group_levels |
Vector/List: a named vector/list that specifies the
levels and labels of |
facet_r |
Character: name of a |
facet_c |
Character: name of a |
facet_r_levels |
Vector/List: a named vector/list that specifies the
levels and labels of |
facet_c_levels |
Vector/List: a named vector/list that specifies the
levels and labels of |
facet_scale |
Character: Are scales shared across all facets. Refer to
the 'scale' argument in |
facet_space |
Character: Refer to the 'space' argument in
|
x_lab |
Character: x-axis label |
y_lab |
Character: y-axis label |
group_lab |
Character: group variable label |
title |
Character: barplot title |
x_limit |
Numeric vector of length 2: limits for x-axis, e.g.
|
y_limit |
Numeric vector of length 2: limits for y-axis, e.g.
|
x_tick_label |
Vector: x-axis tick marks |
all_xticks |
Logical: |
x_tick_angle |
Numeric: the orientation angle (in [0, 360]) of the x-axis tick marks. By default, the label will be horizontal. |
y_tick_angle |
Numeric: the orientation angle (in [0, 360]) of the y-axis tick marks. By default, the label will be horizontal. |
geoms |
Character vector: specify geometric components to be included
in the plot. Valid geoms are 'boxplot', 'line', 'point', 'sumline'. For
example, if the user needs to create a boxplot with raw data points,
specify |
avg_method |
Character: dicates whether to use |
var_method |
Character: dicates whether to use standard error
( |
y_log |
Logical: |
sample_size |
Logical: |
sample_size_font_size |
Numeric: font size of sample size annotation |
reference_hline |
Numeric vector: locations of horizontal reference line(s) if there is any |
reference_vline |
Numeric vector: locations of vertical reference line(s) if there is any |
subject_show |
Logical: |
add_legend |
Logical: |
legend_pos |
Character: dictates the location where to place the legend. Possible locations are 'left', 'right', 'bottom', 'top'. By default, the legend will be place beneath the actual plot, i.e. ‘legend_pos = ’bottom'' |
all_colors |
Vector of valid color representation: when |
all_linetypes |
Numeric vector: by default, lines of different
categories of |
jitter_factor |
Numeric: determines how much the points are jittered over x-axis when ‘geoms' includes ’point'. By default, 'jitter_factor = 1' |
grids |
Character: control the grids. If 'on' (default), grids will be drawn; if 'x', only grids on x-axis will be drawn; if 'y', only grids on y-axis will be drawn; if 'off', no grids will be drawn |
bw_theme |
Logical: if 'TRUE' (default), black-and-white theme will be
used. Refer to |
randseed |
Numeric: random seed can be set in producing jittered points
when |
return_data |
Logical: |
This function relies on ggplot2 package to create time-profiling plots including: Mean + SD/SE plot, Mean + Median plot, Boxplot, Spaghetti plot and their mixture. Labels can be added to the end of each line using directlabels. Panel plot layout is supported. By default black-and-white theme is used.
An object of class ggplot (if return_data = FALSE
) or a list
of two components: an object of class ggplot and a data frame that used to
generate the plot
Feiyang Niu (Feiyang.Niu@gilead.com)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | library(CommonPlots)
data(koopLME)
# Mean + SE plot
data <- koopLME
data$siblings <- factor(with(data, ifelse(SIBLINGS >= 3, '>= 3', SIBLINGS)),
levels = c(0, 1, 2, '>= 3'))
mean_se_plot <- gg_time_profiling(
data, x = 'TIMETRND', y = 'LOGWAGE', group = 'siblings',
geoms = c('sumline'), avg_method = 'mean',
var_method = 'se', x_lab = 'Time trend',
y_lab = 'Log of hourly wage', group_lab = 'Number of siblings',
title = 'Mean + SE plot'
)
# Median + IQR plot
data <- koopLME
data$siblings <- factor(with(data, ifelse(SIBLINGS >= 3, '>= 3', SIBLINGS)),
levels = c(0, 1, 2, '>= 3'))
sib_labels <- paste('Number of siblings:', levels(data$siblings))
median_iqr_plot <- gg_time_profiling(
data, x = 'TIMETRND', y = 'LOGWAGE', facet_c = 'siblings',
facet_c_levels = setNames(levels(data$siblings), sib_labels),
geoms = c('sumline'), avg_method = 'median',
x_lab = 'Time trend', y_lab = 'Log of hourly wage',
title = 'Median + IQR plot'
)
# Spaghetti plot
data <- koopLME
data <- with(data, data[PERSONID %in% unique(PERSONID)[1:100], ])
spaghetti_plot <- gg_time_profiling(
data, x = 'TIMETRND', y = 'LOGWAGE', subject = 'PERSONID',
geoms = c('line'), x_lab = 'Time trend',
y_lab = 'Log of hourly wage', title = 'Spaghetti plot',
subject_show = TRUE
)
# Box plot over time
data <- koopLME
data$siblings <- factor(with(data, ifelse(SIBLINGS >= 3, '>= 3', SIBLINGS)),
levels = c(0, 1, 2, '>= 3'))
sib_labels <- paste('Number of siblings:', levels(data$siblings))
boxplot <- gg_time_profiling(
data, x = 'TIMETRND', y = 'LOGWAGE', facet_r = 'siblings',
facet_r_levels = setNames(levels(data$siblings), sib_labels),
geoms = c('boxplot', 'point'), x_lab = 'Time trend',
y_lab = 'Log of hourly wage', title = 'Box plot',
sample_size = FALSE, all_xticks = TRUE
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.