yutannihilation / gghighlight

Highlight points and lines in ggplot2
https://yutannihilation.github.io/gghighlight/
Other
522 stars 23 forks source link

Keep colors of unhighlighted #167

Closed yutannihilation closed 3 years ago

yutannihilation commented 3 years ago

Fix #152, Fix #164

devtools::load_all("~/repo/gghighlight/")
#> ℹ Loading gghighlight
#> Loading required package: ggplot2

set.seed(2)
d <- purrr::map_dfr(
  letters,
  ~ data.frame(
    idx = 1:400,
    value = cumsum(runif(400, -1, 1)),
    type = .,
    flag = sample(c(TRUE, FALSE), size = 400, replace = TRUE),
    stringsAsFactors = FALSE
  )
)

# Usual one
ggplot(d) +
  geom_line(aes(idx, value, colour = type)) +
  gghighlight(max(value) > 19)
#> label_key: type

# Preserve the colour and modify alpha instead
ggplot(d) +
  geom_line(aes(idx, value, colour = type)) +
  gghighlight(max(value) > 19,
              unhighlighted_params = list(colour = NULL, alpha = 0.3))
#> label_key: type

Created on 2021-06-05 by the reprex package (v2.0.0)