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

Error with factor in x axis and geom_line()

caayala opened this issue · comments

library(ggplot2)
library(gghighlight)

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
)

# var x as continuous works
ggplot(d, aes(x = idx, y = value, colour = category)) +
  geom_line() + 
  gghighlight(category == 'b', use_group_by = FALSE)
#> label_key: category

# var x as character works as expected
d$idx <- as.character(d$idx)

ggplot(d, aes(x = idx, y = value, colour = category,
              group = category)) +
  geom_line() + 
  gghighlight(category == 'b', use_group_by = FALSE)
#> label_key: category

# var x as factor dosn't works as expected
d$idx <- as.factor(d$idx)

ggplot(d, aes(x = idx, y = value, colour = category,
              group = category)) +
  geom_line() + 
  gghighlight(category == 'b', use_group_by = FALSE)
#> label_key: category
#> Error: Problem with `filter()` input `..1`.
#> x 'max' not meaningful for factors
#> ℹ Input `..1` is `idx == max(idx)`.
#> ℹ The error occurred in group 1: category = "b".

cc @vicky-rojas.

Created on 2020-10-27 by the reprex package (v0.3.0)

Thanks, confirmed. I'll fix this soon...