Search code examples
rggplot2tidyversevisualizationgghighlight

I am a little confused by how does `gghighlight` work with non-logical (min / max) predicates


I don't understand how these plots differ from each other. I tweaked around with min, max, -min, and -max. But I don't really understand how and what these do!

library(tidyverse)
library(gghighlight)
library(patchwork)


A <- ggplot(d, aes(idx, value, colour = type)) +
  geom_line() +
  gghighlight(max(value), max_highlight = 5L)

B <- ggplot(d, aes(idx, value, colour = type)) +
  geom_line() +
  gghighlight(-max(value), max_highlight = 5L)

C <- ggplot(d, aes(idx, value, colour = type)) +
  geom_line() +
  gghighlight(min(value), max_highlight = 5L)

D <- ggplot(d, aes(idx, value, colour = type)) +
  geom_line() +
  gghighlight(-min(value), max_highlight = 5L)

(A + B) / (C + D) + patchwork::plot_annotation(tag_levels = "A")

enter image description here


Solution

  • So I thought more about the question and here is the answer:

    1. Plot A highlights the lines with maximums of the top 5.
    2. Plot B highlights the lines with maximums of the bottom 5.
    3. Plot C highlights the lines with minimums of the top 5.
    4. Plot D highlights the lines with minimums of the bottom 5.