Creates scatter plots with Insper's visual identity, with an optional fitted line. Accepts both color and fill aesthetics, so outlined point shapes can carry two mappings.
Usage
insper_scatterplot(
data,
x,
y,
color = NULL,
fill = NULL,
palette = "main",
add_smooth = FALSE,
smooth_method = "lm",
point_size = 2,
point_alpha = 1,
...
)Arguments
- data
A data frame.
- x
<
data-masked> Variable for the x-axis.- y
<
data-masked> Variable for the y-axis.- color
Color aesthetic. Accepts one of the options below.
A bare column name, mapped to color (e.g.,
color = Species).A quoted color string, used as a static color (e.g.,
color = "blue").NULL(default), which uses Insper turquesa.
A mapped variable gets a discrete or continuous Insper scale to match its type.
- fill
Fill aesthetic, for outlined shapes 21 to 25. Accepts one of the options below.
A bare column name, mapped to fill (e.g.,
fill = Species).A quoted color string, used as a static fill (e.g.,
fill = "lightblue").NULL(default), for no fill.
- palette
Character. Palette for mapped variables. Default is
"main".- add_smooth
Logical. If
TRUE, adds a fitted line with a confidence band. Default isFALSE.- smooth_method
Character. Smoothing method:
"lm"(default),"loess","gam", or"glm".- point_size
Numeric. Point size. Default is 2.
- point_alpha
Numeric. Point opacity, from 0 to 1. Default is 1.
- ...
Additional arguments passed to
ggplot2::geom_point(), such asshapeorstroke.
Details
Solid shapes (16 to 20) use only color. Outlined shapes (21 to 25) use
color for the outline and fill for the interior, so you can map a
different variable, or a static color, to each.
Examples
if (FALSE) { # has_insper_fonts()
# Simple scatter plot with default color
insper_scatterplot(mtcars, x = wt, y = mpg)
# Discrete variable mapping
insper_scatterplot(mtcars, x = wt, y = mpg, color = factor(cyl))
# With smooth line
insper_scatterplot(mtcars, x = wt, y = mpg, add_smooth = TRUE)
# Extra arguments go to geom_point()
insper_scatterplot(mtcars, x = wt, y = mpg, size = 3, alpha = 0.5)
# Shape 21 with static color and mapped fill
insper_scatterplot(mtcars, x = wt, y = mpg,
color = "white",
fill = factor(cyl),
shape = 21)
}
