lollipop | R Documentation |
This function creates a lollipop chart (by default), a points chart (if sticks = FALSE
) or a point-range chart (if sticks
are confidence limits) from a (named) numeric vector.
lollipop(x, names = NULL, ymin = 0, ylim = "auto0", sticks = TRUE,
col = "royalblue4", grid = TRUE, cex = 1, cex.axis = 1, las = 2,
horiz = FALSE, bold = FALSE, ...)
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 (default 0). If set to NA, the minimum of 'x' will be used. This argument is deprecated, as it is now superseded by, and should be replaced with, 'ylim' (below). |
ylim |
either a numeric vector of length 2 specifying the limits (minimum, maximum) for the y axis; or "auto" to fit the y axis to the minimum and maximum existing values in 'x'; or "auto0" (the new default) to fit the top of the y axis to the maximum existing values, and the bottom to zero or the minimum existing value (whichever is lower). If |
sticks |
either a logical value indicating whether the sticks of the lollipops (lines from zero to each value) should be drawn (default TRUE); or a two-column matrix or dataframe with one row for each element in x, with the minimum and maximum values for the error bars or confidence intervals (in which case a point-range chart is drawn). |
col |
colour for the lollipops. |
grid |
logical value (default TRUE) indicating whether or not to add a grid to the plot. |
cex |
numeric value indicating the size of the lollipops. Will be passed as 'cex' to |
cex.axis |
numeric value to pass to |
las |
argument to pass to |
horiz |
logical value (default FALSE) indicating whether the plot should be drawn horizontally rather than vertically. |
bold |
logical vector (recycled if shorter than |
... |
additional arguments that can be passed to |
According to modern data viz recommendations, lollipop charts (or instead point 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 visually compare the values.
A plot.
A. Marcia Barbosa
plotCoeffs
; barplot
; ggplot2::geom_pointrange()
par(mar = c(6, 3, 2, 1))
lollipop(mtcars[,1], names = rownames(mtcars), las = 2,
ylab = names(mtcars)[1], cex.axis = 0.6)
lollipop(mtcars[,1], names = rownames(mtcars), las = 2,
ylab = names(mtcars)[1], cex.axis = 0.6, ylim = NA)
par(mar = c(3, 6, 2, 1))
lollipop(mtcars[,1], names = rownames(mtcars), las = 2,
xlab = "Miles/gallon", cex.axis = 0.6, main = "Lollipop chart of mtcars",
horiz = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.