Learn R Programming

modEvA (version 3.18.2)

lollipop: 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, ...)

Value

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

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'.

Author

A. Marcia Barbosa

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.

See Also

Examples

Run this code
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)

Run the code above in your browser using DataLab