lollipop: Lollipop chart

View source: R/lollipop.R

lollipopR Documentation

Lollipop chart

Description

This function creates a lollipop chart from a (optionally named) numeric vector.

Usage

  lollipop(x, names = NULL, ymin = 0, sticks = TRUE, col = "royalblue",
  grid = TRUE, cex = 1, cex.axis = 1, las = 2, ...)

Arguments

x

a numeric vector.

names

a vector of the same length as 'x' with the names to be plotted below the lollipops. If this argument is left NULL and 'x' has names, then these will be used.

ymin

numeric value for the lower limit of the y axis. The default is zero. If set to NA, the minimum of 'x' will be used.

sticks

logical value indicating whether the sticks of the lollipops should be drawn. The default is TRUE.

col

colour for the lollipops.

grid

logical, whether or not to add a grid to the plot. The default is TRUE.

cex

numeric value indicating the size of the lollipops. Will be passed as 'cex' to 'points' and as 'lwd' to 'arrows' (the lines or lollipop sticks).

cex.axis

numeric value indicating the size of the x and y axis labels.

las

argument to pass to par indicating the orientation of the axis labels.

...

additional arguments that can be used for the plot, e.g. 'main'.

Details

According to modern data viz recommendations, lollipop charts are generally a better alternative to bar charts, as they reduce the visual distortion caused by the length of the bars, making it easier to compare the values.

Value

This function produces a lollipop chart of the values in 'x'.

Author(s)

A. Marcia Barbosa

See Also

barplot

Examples

lollipop(mtcars[,1], names = rownames(mtcars), las = 2, ylab = names(mtcars)[1],
cex.axis = 0.6, main = "Lollipop chart")

lollipop(mtcars[,1], names = rownames(mtcars), las = 2, ylab = names(mtcars)[1],
cex.axis = 0.6, main = "Lollipop chart", ymin = NA)

modEvA documentation built on March 25, 2024, 3 p.m.