View source: R/sm_slope_mean.R
sm_slope_mean | R Documentation |
Generates a slope chart with mean for a single group. This is useful for comparing the effect between two time points. The function includes options for shadow lines and points, mean lines, points, and error bars, all of which can be customized.
Note: This functionality can also be reproduced using 'sm_slope()' with appropriate customization. In 'ggplot()', the mapping requires grouping each observation to correctly pair points.
sm_slope_mean(
...,
labels,
group,
main_color = sm_color("blue"),
main_shape = 21,
back_alpha = 0.25,
line_width = 0.25,
avgline_width = 1,
point_size = 2.5,
avgpoint_size = 4,
err_width = 1,
xTick.params = list(position = "top", expand = c(0.17, 0.1), drop = FALSE),
errorbar_type = "sd",
show_err = FALSE,
legends = FALSE
)
... |
Additional aesthetic parameters applied across points, lines, and error bars. Optional. |
labels |
A vector specifying the labels for the x-axis ticks. This is a required argument.
For example: |
group |
The name of the variable used to group individual data points. This is a required argument. |
main_color |
The main color of the slope chart, shared across:
Default: |
main_shape |
The shape of the points in the slope chart:
Default: |
back_alpha |
Transparency (alpha) for the shadow lines and points:
Default: |
line_width |
Line width for the shadow lines connecting points. Default: |
avgline_width |
Line width for the average line. Default: |
point_size |
Size of the points in the shadow. Default: |
avgpoint_size |
Size of the points representing the mean of the data. Default: |
err_width |
Line width for the error bars. Default: |
xTick.params |
A list of parameters for customizing the x-axis ticks. Options include:
|
errorbar_type |
A string specifying the type of error bars to display:
|
show_err |
Logical. Determines whether to display error bars:
|
legends |
Logical. Determines whether to display legends:
|
A slope chart with mean, represented as a ggplot2 object.
library(ggplot2)
library(smplot2)
set.seed(1) # generate random data
day1 = rnorm(16,2,1)
day2 = rnorm(16,5,1)
Subject <- rep(paste0('S',seq(1:16)), 2)
Data <- data.frame(Value = matrix(c(day1,day2),ncol=1))
Day <- rep(c('Day 1', 'Day 2'), each = length(day1))
df <- cbind(Subject, Data, Day)
ggplot(data=df, aes(x = Day, y = Value)) +
sm_slope_mean(labels = c('Day 1', 'Day 2'), group = Subject, back_alpha = .3,
main_color = sm_color('green'))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.