Learn R Programming

daltoolbox (version 1.2.747)

plot_lollipop: Plot lollipop

Description

Lollipop chart (stick + circle + value label) per category.

Usage

plot_lollipop(
  data,
  label_x = "",
  label_y = "",
  colors = NULL,
  color_text = "black",
  size_text = 3,
  size_ball = 8,
  alpha_ball = 0.2,
  min_value = 0,
  max_value_gap = 1
)

Value

returns a ggplot2::ggplot graphic

Arguments

data

data.frame with category and numeric values

label_x

x‑axis label

label_y

y‑axis label

colors

stick/circle color

color_text

color of the text inside the circle

size_text

text size

size_ball

circle size

alpha_ball

circle transparency (0–1)

min_value

minimum baseline for the stick

max_value_gap

gap from value to stick end

Details

Expects a data.frame with category in the first column and numeric values in subsequent columns. Circles are drawn at values, with vertical segments extending from min_value to value - max_value_gap.

Examples

Run this code
#summarizing iris dataset
data <- iris |> dplyr::group_by(Species) |>
dplyr::summarize(Sepal.Length=mean(Sepal.Length))
head(data)

#ploting data
grf <- plot_lollipop(data, colors="blue", max_value_gap=0.2)
plot(grf)

Run the code above in your browser using DataLab