Learn R Programming

nomiShape (version 1.0.0)

centered_dotplot: Centered Dot Plot for Nominal Variables

Description

Creates a centered dot plot for a nominal variable, ordering categories from the most frequent at the center toward less frequent categories on both sides. Optionally connects points with a line and shades the area under the line.

Usage

centered_dotplot(
  df,
  var,
  connect = FALSE,
  shade = FALSE,
  scale = c("count", "percent")
)

Value

A ggplot2 object.

Arguments

df

A data.frame or tibble containing the variable.

var

Character. Name of the nominal variable in df.

connect

Logical; if TRUE, connects points with a line.

shade

Logical; if TRUE, shades the area under the line (requires connect = TRUE).

scale

Character; either "count" (default) or "percent".

Examples

Run this code
centered_dotplot(categories, "animal")
centered_dotplot(categories, "animal", connect = TRUE)
centered_dotplot(categories, "animal", connect = TRUE, shade = TRUE)
centered_dotplot(mpg, "manufacturer", scale = "percent")

Run the code above in your browser using DataLab