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
)
# Highlight the lines whose max values are larger than 10
ggplot(d, aes(idx, value, colour = category)) +
geom_line() + gghighlight(max(value) > 10)
# Highlight the points whose values are larger than 10
ggplot(d, aes(idx, value)) +
geom_point() +
gghighlight(value > 10, label_key = category)
# Specify the styles for unhighlighted layer
ggplot(d, aes(idx, value, colour = category)) +
geom_line(linewidth = 5) +
gghighlight(max(value) > 10,
unhighlighted_params = list(linewidth = 1)
)
Run the code above in your browser using DataLab