The ggcharts
package currently offers two functions with
a highlight
parameter: bar_chart()
and
lollipop_chart()
. The usage is the same for both
functions.
In its most simple form the highlight
feature can be
used to highlight a single bar or lollipop.
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"
)
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
)
To highlight more than one value pass a vector to
highlight
.
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
)