sm_slope | R Documentation |
Generates a slope chart, which is particularly useful for comparing effects between two time points. The function supports grouped data and provides various customization options for lines, points, error bars, and x-axis ticks. Users can specify the type of error bars and control whether to display mean and error bars.
The mapping in 'ggplot()' requires grouping each observation to ensure correct pairing of points.
sm_slope(
...,
labels,
group,
line.params = list(color = "gray53", linewidth = 0.4, alpha = 0.4),
point.params = list(size = 2.5, shape = 21, color = "white"),
avgLine.params = list(linewidth = 1),
avgPoint.params = list(size = 4),
err.params = list(linewidth = 1),
xTick.params = list(position = "top", expand = c(0.17, 0.1), drop = FALSE),
errorbar_type = "sd",
many_groups = FALSE,
show_err = FALSE,
show_mean = FALSE,
legends = FALSE,
forget = FALSE
)
... |
Additional aesthetic parameters applied across points and lines, such as |
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. |
line.params |
A list of parameters for individual lines. Common parameters include:
Default: |
point.params |
A list of parameters for individual points. Common parameters include:
Default: |
avgLine.params |
A list of parameters for the average line. Common parameters include:
Default: |
avgPoint.params |
A list of parameters for the average points. Common parameters include:
Default: |
err.params |
A list of parameters for error bars. Common parameters include:
Default: |
xTick.params |
A list of parameters for customizing the x-axis ticks. Common options include:
|
errorbar_type |
A string specifying the type of error bars to display:
|
many_groups |
Logical. Determines whether the average line is plotted for each group:
Default: |
show_err |
Logical. Determines whether to display error bars:
|
show_mean |
Logical. Determines whether to display the average line and points:
|
legends |
Logical. Determines whether to display legends:
|
forget |
Logical. Determines whether to apply the default aesthetic parameters:
|
A list of ggplot2 layers for creating a slope chart.
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, fill = Day)) +
sm_slope(labels = c('Day 1', 'Day 2'), group = Subject) +
scale_fill_manual(values= sm_color('blue','orange'))
ggplot(data = df, aes(x = Day, y = Value, fill = Day)) +
sm_slope(labels = c('Day 1','Day 2'),group = Subject,
point.params = list(alpha = 0.3, size = 2.5, color = 'white',
shape = 21, fill = sm_color('skyblue')),
line.params = list(color = sm_color('skyblue'),
alpha = 0.3),
avgPoint.params = list(color='transparent', shape = 21,
size = 4, fill = sm_color('blue')),
avgLine.params = list(color = sm_color('blue'), linewidth = 1),
show_mean = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.