The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Make Your Plots Stand Out with Highlights

Introduction

The ggcharts package currently offers two functions with a highlight parameter: bar_chart() and lollipop_chart(). The usage is the same for both functions.

library(ggcharts)
library(dplyr)
data("biomedicalrevenue")
revenue2018 <- biomedicalrevenue %>%
  filter(year == 2018)

Basic Usage

In its most simple form the highlight feature can be used to highlight a single bar or lollipop.

bar_chart(
  revenue2018,
  company,
  revenue,
  top_n = 10,
  highlight = "Roche"
)

The color for the highlighted and non-highlighted values are automatically determined from the currently active ggcharts theme, i.e. ggcharts_get_theme(). Thus, changing the theme will change these colors.

ggcharts_set_theme("theme_ng")
bar_chart(
  revenue2018,
  company,
  revenue,
  top_n = 10,
  highlight = "Roche"
)

Changing the (Non-)Highlight Color

To set the highlight and non-highlight colors manually you will need to pass a highlight_spec() to the highlight argument.

ggcharts_set_theme("theme_ggcharts")
spec <- highlight_spec(
  what = "Roche",
  highlight_color = "black",
  other_color = "lightgray"
)
bar_chart(
  revenue2018,
  company,
  revenue,
  top_n = 10,
  highlight = spec
)

Highlighting Multiple Data Points

To highlight more than one value pass a vector to highlight.

bar_chart(
  revenue2018,
  company,
  revenue,
  top_n = 10,
  highlight = c("Roche", "Novartis")
)

To highlight multiple values in different colors you will need to use a highlight_spec() again.

spec <- highlight_spec(
  what = c("Roche", "Novartis"),
  highlight_color = c("steelblue", "darkorange")
)
lollipop_chart(
  revenue2018,
  company,
  revenue,
  top_n = 10,
  highlight = spec
)

Highlight + Facet

The highlight feature is particularly useful when used in conjunction with the facet feature.

biomedicalrevenue %>%
  filter(year %in% c(2012, 2014, 2016, 2018)) %>%
  bar_chart(
    company,
    revenue,
    facet = year,
    top_n = 12,
    highlight = "Bayer"
  )

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.