似乎确实是这样:
library(tidyverse)
library(gghighlight)
mtcars <- mtcars
#using geom_point insted of geom_jitter since geom_jitter adds noise to the points, thus making plots tougher to reproduce and compare:
#no highlight:
ggplot()+
geom_point(mtcars, mapping = aes(x = factor(cyl),y = wt,col = factor(gear)), show.legend = FALSE,, position=position_dodge(width = 0.5))
#with highlight:
ggplot()+
geom_point(mtcars, mapping = aes(x = factor(cyl),y = wt,col = factor(gear)), show.legend = FALSE, position=position_dodge(width = 0.5))+
gghighlight(wt > 3,label_key = gear)
请参阅标有“3”的红色点左侧的 cyl=6 的灰色点。
#new points seem to appear for cyl=6 (grey ones to the left), so lets look at these specifically:
#first: how many values should be there?
only_cyl_6 <- subset(mtcars, mtcars$cyl==6)
length(only_cyl_6$wt)
#7
#but we see 6 points in our first plot. A quick look @ only_cyl_6 reveals that #two values have the same wt value:
only_cyl_6
# -> Merc 280 & Merc 280C
#so the first plot seems to be fine...geom_jitter supports this.
ggplot()+
geom_jitter(only_cyl_6, mapping = aes(x = factor(cyl),y = wt,col = factor(gear)), show.legend = FALSE)
#now we see 7 point. thats good.
#lets add highlight again:
ggplot()+
geom_jitter(only_cyl_6, mapping = aes(x = factor(cyl),y = wt,col = factor(gear)), show.legend = FALSE)+
gghighlight(wt > 3,label_key = gear)
现在有 9 个。总而言之:添加高亮似乎确实会绘制额外的点......