diverging_lollipop_chart: Diverging Lollipop Chart

Description Usage Arguments Value Author(s) See Also Examples

View source: R/diverging_chart.R

Description

Easily create a diverging lollipop chart

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
diverging_lollipop_chart(
  data,
  x,
  y,
  lollipop_colors = c("#1F77B4", "#FF7F0E"),
  line_size = 0.75,
  point_size = 3,
  text_color = "auto",
  text_size = 10
)

Arguments

data

Dataset to use for the diverging lollipop chart

x

character or factor column of data

y

numeric column of data representing the lollipop length

lollipop_colors

A character vector of length 2 containing the colors for the positive and negative lollipops

line_size

numeric. Size of the lollipop 'stick'

point_size

numeric. Size of the lollipop 'head'

text_color

character. The color for the lollipop annotations

text_size

numeric The size of the lollipop annotation text in pt

Value

An object of class ggplot

Author(s)

Thomas Neitmann

See Also

To learn how to further customize this plot have a look at the 'customize' vignette: 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
if (requireNamespace("tidyr")) {
  library(magrittr)
  data(biomedicalrevenue)
  biomedicalrevenue %>%
  dplyr::filter(year > 2016) %>%
  tidyr::pivot_wider(
    values_from = revenue,
    names_from = year,
    names_prefix = "revenue_"
  ) %>%
  dplyr::mutate(diff = revenue_2018 - revenue_2017) %>%
  diverging_lollipop_chart(company, diff)
}

data(mtcars)
mtcars_z <- dplyr::transmute(
  .data = mtcars,
  model = row.names(mtcars),
  hpz = scale(hp)
)

diverging_lollipop_chart(mtcars_z, model, hpz)

## Change the colors
diverging_lollipop_chart(mtcars_z, model, hpz, lollipop_colors = c("darkgreen", "darkred"))

## Decrease the axis label font size
diverging_lollipop_chart(mtcars_z, model, hpz, text_size = 8)

## Display the axis label text in the same color as the bars
diverging_lollipop_chart(mtcars_z, model, hpz, text_color = c("#1F77B4", "#FF7F0E"))

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