yutannihilation / gghighlight

Highlight points and lines in ggplot2

Home Page:https://yutannihilation.github.io/gghighlight/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot sort by min

antonwnk opened this issue · comments

My use-case involves using a non-logical predicate with max_highlight to highlight the lowest values in my set of lines, however, I find that replacing the max function in the vignette example with min does not work and still outputs the max:

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
    )
)

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

000011

It does work to use -max(.) instead of min(.) (i.e. something else gets plotted) but that's not equivalent, unfortunately, as it only reverses the order of the maximum values in each line.

Ah, it might be a bit tricky. By using min(), you are highlighting the lines whose minimum values are the highest. I guess what you want is -min(), right?

Ahh! That's right, my mistake.
Thanks for clearing it up. 😀