View source: R/geom_parallel_slopes.R
geom_parallel_slopes | R Documentation |
geom_parallel_slopes()
fits parallel slopes model and adds its line
output(s) to a ggplot
object. Basically, it fits a unified model with
intercepts varying between groups (which should be supplied as standard
{ggplot2}
grouping aesthetics: group
, color
, fill
,
etc.). This function has the same nature as geom_smooth()
from
{ggplot2}
package, but provides functionality that geom_smooth()
currently doesn't have.
geom_parallel_slopes(
mapping = NULL,
data = NULL,
position = "identity",
...,
se = TRUE,
formula = y ~ x,
n = 100,
fullrange = FALSE,
level = 0.95,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
se |
Display confidence interval around model lines? |
formula |
Formula to use per group in parallel slopes model. Basic
linear |
n |
Number of points per group at which to evaluate model. |
fullrange |
If |
level |
Level of confidence interval to use (0.95 by default). |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom_categorical_model()
library(dplyr)
library(ggplot2)
ggplot(evals, aes(x = age, y = score, color = ethnicity)) +
geom_point() +
geom_parallel_slopes(se = FALSE)
# Basic usage
ggplot(evals, aes(x = age, y = score, color = ethnicity)) +
geom_point() +
geom_parallel_slopes()
ggplot(evals, aes(x = age, y = score, color = ethnicity)) +
geom_point() +
geom_parallel_slopes(se = FALSE)
# Supply custom aesthetics
ggplot(evals, aes(x = age, y = score, color = ethnicity)) +
geom_point() +
geom_parallel_slopes(se = FALSE, size = 4)
# Fit non-linear model
example_df <- house_prices %>%
slice(1:1000) %>%
mutate(
log10_price = log10(price),
log10_size = log10(sqft_living)
)
ggplot(example_df, aes(x = log10_size, y = log10_price, color = condition)) +
geom_point(alpha = 0.1) +
geom_parallel_slopes(formula = y ~ poly(x, 2))
# Different grouping
ggplot(example_df, aes(x = log10_size, y = log10_price)) +
geom_point(alpha = 0.1) +
geom_parallel_slopes(aes(fill = condition))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.