To put it simply, gghighlight doesn’t drop any data points but drops their colours. This means, while non-colour scales (e.g. x, y and size) are kept as they are, colour scales get shrinked. This might be inconvenient when we want to compare the original version and the highlighted version, or the multiple highlighted versions.
library(gghighlight)
Loading required package: ggplot2
library(patchwork)set.seed(3)d <-data.frame(value =1:9,category =rep(c("a","b","c"), 3),cont_var =runif(9),stringsAsFactors =FALSE)p <-ggplot(d, aes(x = category, y = value, color = cont_var)) +geom_point(size =10) +scale_colour_viridis_c()p1 <- p +ggtitle("original")p2 <- p +gghighlight(dplyr::between(cont_var, 0.3, 0.7),use_direct_label =FALSE) +ggtitle("highlighted")
Warning: Tried to calculate with group_by(), but the calculation failed.
Falling back to ungrouped filter operation...
p1 * p2
You can see the colour of the points are different between the left plot and the right plot because the scale of the colours are different. In such a case, you can specify keep_scale = TRUE to keep the original scale (under the hood, gghighlight simply copies the original data to geom_blank()).
But, it sometimes feels better to highlight facet by facet. For such a need, gghighlight() now has a new argument calculate_per_facet.
p +gghighlight(mean(value) >0,calculate_per_facet =TRUE,keep_scales =TRUE)
label_key: id
Note that, as a general rule, only the layers before adding gghighlight() are modified. So, if you add facet_*() after adding gghighlight(), this option doesn’t work (though this behaviour might also be useful in some cases).
gghighlight() now allows users to override the parameters of unhighlighted data via unhighlighted_params. This idea was suggested by @ClausWilke.
I think you could support a broader set of use cases if you allowed a list of aesthetics default values, like bleach_aes = list(colour = "grey40", fill ="grey80", size = 0.2).
To illustrate the original motivation, let’s use an example on the ggridges’ vignette. gghighlight can highlight almost any Geoms, but it doesn’t mean it can “unhighlight” arbitrary colour aesthetics automatically. In some cases, you need to unhighlight them manually. For example, geom_density_ridges() has point_colour.
You should notice that these vertical lines still have their colours. To grey them out, we can specify point_colour = "grey80" on unhighlighted_params (Be careful, point_color doesn’t work…).
p +gghighlight(sd(height) <5.5, unhighlighted_params =list(point_colour ="grey80"))
Picking joint bandwidth of 2.8
Picking joint bandwidth of 2.23
unhighlighted_params is also useful when you want more significant difference between the highlighted data and unhighligted ones. In the following example, size and colour are set differently.
size aesthetic has been deprecated for use with lines as of ggplot2 3.4.0
i Please use linewidth aesthetic instead
label_key: type
This message is displayed once every 8 hours.