yutannihilation / gghighlight

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

Change unhighlighted colour when ink is lighter than paper #211

Closed yutannihilation closed 1 month ago

yutannihilation commented 1 month ago
devtools::load_all("~/GitHub/gghighlight/")
#> ℹ Loading gghighlight
#> Loading required package: ggplot2

p1 <- ggplot(mtcars, aes(wt, mpg)) + 
  geom_point(size = 5) +
  theme(geom = element_geom(ink = "purple")) +
  gghighlight(mpg < 25)

do_plot <- function(ink = "black", paper = "white") {
  p <- ggplot(mtcars, aes(wt, mpg)) + 
    geom_point(size = 5) +
    theme(
      geom = element_geom(ink = ink, paper = paper),
      plot.background = element_rect(fill = paper),
      panel.background = element_rect(fill = paper)
    ) +
    gghighlight(mpg < 25)
}

p2 <- do_plot()
p3 <- do_plot("purple")
p4 <- do_plot("white", "black")
p5 <- do_plot("white", "red")
p6 <- do_plot("blue", "red")

patchwork::wrap_plots(p1, p2, p3, p4, p5, p6)

Created on 2024-09-07 with reprex v2.1.1