lollipop_chart: Lollipop Chart

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/lollipop_chart.R

Description

Easily create a lollipop chart

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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.

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.

Value

An object of class ggplot

Author(s)

Thomas Neitmann

See Also

For more details have a look at these vignettes: vignette("highlight", package = "ggcharts") vignette("customize", package = "ggcharts")

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)

thomas-neitmann/ggcharts documentation built on Oct. 8, 2021, 1:17 a.m.