Description Usage Arguments Value Author(s) See Also Examples
View source: R/diverging_chart.R
Easily create a diverging bar chart
1 2 3 4 5 6 7 8  | diverging_bar_chart(
  data,
  x,
  y,
  bar_colors = c("#1F77B4", "#FF7F0E"),
  text_color = "auto",
  text_size = 10
)
 | 
data | 
 Dataset to use for the diverging bar chart  | 
x | 
 
  | 
y | 
 
  | 
bar_colors | 
 A   | 
text_color | 
 
  | 
text_size | 
 
  | 
An object of class ggplot
Thomas Neitmann
To learn how to further customize this plot have a look at the 'customize' vignette:
vignette("customize", package = "ggcharts")
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_bar_chart(company, diff)
}
data(mtcars)
mtcars_z <- dplyr::transmute(
  .data = mtcars,
  model = row.names(mtcars),
  hpz = scale(hp)
)
diverging_bar_chart(mtcars_z, model, hpz)
## Change the colors
diverging_bar_chart(mtcars_z, model, hpz, bar_color = c("darkgreen", "darkred"))
## Decrease the axis label font size
diverging_bar_chart(mtcars_z, model, hpz, text_size = 8)
## Display the axis label text in the same color as the bars
diverging_bar_chart(mtcars_z, model, hpz, text_color = c("#1F77B4", "#FF7F0E"))
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.