Easily create a lollipop chart

lollipop_chart(
  data,
  x,
  y,
  facet = NULL,
  ...,
  line_size = 0.75,
  line_color = "auto",
  point_size = 4,
  point_color = line_color,
  highlight = NULL,
  sort = TRUE,
  horizontal = TRUE,
  top_n = NULL,
  threshold = NULL,
  other = FALSE,
  limit = NULL
)

Arguments

data

Dataset to use for the bar chart

x

character or factor column of data

y

numeric column of data representing the lollipop length. If missing, the lollipop length will be proportional to the count of each value in x.

facet

character or factor column of data defining the faceting groups

...

Additional arguments passed to aes()

line_size

numeric. Size of the lollipop 'stick'

line_color

character. Color of the lollipop 'stick'

point_size

numeric. Size of the lollipop 'head'

point_color

character. Color of the lollipop 'head'

highlight

character. One or more value(s) of x that should be highlighted in the plot

sort

logical. Should the data be sorted before plotting?

horizontal

logical. Should the plot be oriented horizontally?

top_n

numeric. If a value for top_n is provided only the top top_n records will be displayed

threshold

numeric. If a value for threshold is provided only records with y > threshold will be displayed

other

logical. Should all x with y < threshold be summarized in a group called 'other' and be displayed at the bottom of the chart?

limit

Deprecated. use top_n instead.

Value

An object of class ggplot

Details

Both top_n and threshold only work when sort = TRUE. Attempting to use them when sort = FALSE will result in an error. Furthermore, only top_n or threshold can be used at a time. Providing a value for both top_n and threshold will result in an error as well.

See also

Examples

data(biomedicalrevenue) revenue2016 <- biomedicalrevenue[biomedicalrevenue$year == 2016, ] revenue_bayer <- biomedicalrevenue[biomedicalrevenue$company == "Bayer", ] ## By default lollipop_chart() creates a horizontal and sorted plot lollipop_chart(revenue2016, company, revenue)
## If the `y` argument is missing the count of each value in `x` is displayed lollipop_chart(mtcars, cyl)
## Create a vertical, non-sorted lollipop chart lollipop_chart(revenue_bayer, year, revenue, horizontal = FALSE, sort = FALSE)
## Limit the number of lollipops to the top 15 lollipop_chart(revenue2016, company, revenue, top_n = 15)
## Display only companies with revenue > 50B. lollipop_chart(revenue2016, company, revenue, threshold = 50)
## Change the color of the whole lollipop lollipop_chart(revenue2016, company, revenue, line_color = "purple")
## Change the color of the lollipop stick and head individually lollipop_chart(revenue2016, company, revenue, point_color = "darkgreen", line_color = "gray")
## Decrease the lollipop head size lollipop_chart(revenue2016, company, revenue, point_size = 2.5)
## Highlight a single lollipop lollipop_chart(revenue2016, company, revenue, top_n = 15, highlight = "Roche")
## Use facets to show the top 10 companies over the years lollipop_chart(biomedicalrevenue, company, revenue, facet = year, top_n = 10)