Skip to contents

Creates density plots with Insper's visual identity. Supports grouped densities, with one color per group.

Usage

insper_density(
  data,
  x,
  fill = NULL,
  palette = NULL,
  fill_color = get_insper_colors("turquesa_3"),
  line_color = get_insper_colors("turquesa_2"),
  alpha = 0.6,
  bw = "nrd0",
  adjust = 1,
  kernel = "gaussian",
  ...
)

Arguments

data

A data frame.

x

<data-masked> Numeric variable for the x-axis.

fill

Fill aesthetic. Accepts one of the options below.

  • A quoted color string, used as a static color (e.g., "purple", "#9148B0").

  • A bare discrete column or factor expression, used for grouping (e.g., Species or factor(gear)).

  • NULL (default), which uses Insper turquesa.

The fill color also sets the density line color.

palette

Character. Palette for mapped variables. If NULL (default), uses "main".

fill_color

Character. Area color, used only when fill is NULL. Default is turquesa_3. Prefer fill = "<color>", which colors both the area and the line.

line_color

Character. Line color, used only when fill is NULL. Default is turquesa_2, a lighter step of the turquesa ramp.

alpha

Numeric. Area opacity, from 0 to 1. Default is 0.6.

bw

Numeric or character. Bandwidth, either a number or the name of a bandwidth selector ("nrd0", "nrd", "ucv", "bcv", "SJ"). Default is "nrd0".

adjust

Numeric. Multiplier applied to the bandwidth. Default is 1.

kernel

Character. Smoothing kernel. Default is "gaussian".

...

Additional arguments passed to ggplot2::geom_density().

Value

A ggplot object.

Examples

if (FALSE) { # has_insper_fonts()
# Simple density plot (default turquesa)
insper_density(macro_series, x = ipca)

# Static color
insper_density(macro_series, x = ipca, fill = "purple")

# Grouped density plot (discrete variable)
insper_density(iris, x = Sepal.Length, fill = Species)
}