gghighlight: Highlight Data With Predicate

Description Usage Arguments Examples

View source: R/gghighlight.R

Description

gghiglight() highlights (almost) any geoms according to the given predicates.

Usage

1
2
3
4
gghighlight(..., n = NULL, max_highlight = 5L,
  unhighlighted_colour = ggplot2::alpha("grey", 0.7), use_group_by = NULL,
  use_direct_label = NULL, label_key = NULL, label_params = list(fill =
  "white"))

Arguments

...

Expressions to filter data, which is passed to dplyr::filter().

n

Number of layers to clone.

max_highlight

Max number of series to highlight.

unhighlighted_colour

Colour for unhighlighted geoms.

use_group_by

If TRUE, use dplyr::group_by() to evaluate predicate.

use_direct_label

If TRUE, add labels directly on the plot instead of using a legend.

label_key

Column name for label aesthetics.

label_params

A list of parameters, which is passed to ggrepel::geom_label_repel().

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
d <- data.frame(
  idx = c( 1, 1, 1, 2, 2, 2, 3, 3, 3),
  value = c( 1, 2, 3,10,11,12, 9,10,11),
  category = rep(c("a","b","c"), 3),
  stringsAsFactors = FALSE
)

# highlight the lines whose max values are larger than 10
ggplot(d, aes(idx, value, colour = category)) +
  geom_line() + gghighlight(max(value) > 10)

# highlight the points whose values are larger than 10
ggplot(d, aes(idx, value)) +
  geom_point() +
  gghighlight(value > 10, label_key = category)

yutannihilation/gghighlight documentation built on July 6, 2018, 12:43 a.m.