Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R GG突出显示创建额外的点_R_Ggplot2_Gghighlight - Fatal编程技术网

R GG突出显示创建额外的点

R GG突出显示创建额外的点,r,ggplot2,gghighlight,R,Ggplot2,Gghighlight,当我高亮显示时,gghighlight似乎在创建额外的点。有什么建议吗?我想我一定是做错了什么 library(tidyverse) library(gghighlight) mtcars<-mtcars #produces as expected ggplot(mtcars) + geom_jitter(aes(x=factor(cyl),y=wt,col=factor(gear)),show.legend = FALSE) #produces as expected #cre

当我高亮显示时,gghighlight似乎在创建额外的点。有什么建议吗?我想我一定是做错了什么

library(tidyverse)
library(gghighlight)
mtcars<-mtcars

#produces as expected
ggplot(mtcars) + 
  geom_jitter(aes(x=factor(cyl),y=wt,col=factor(gear)),show.legend = FALSE)
#produces as expected

#creates extra points?
ggplot(mtcars) + 
  geom_jitter(aes(x=factor(cyl),y=wt,col=factor(gear)),show.legend = FALSE)+gghighlight::gghighlight(wt>3,label_key = gear)
库(tidyverse)
图书馆(GG)
mtcars3,标签(钥匙=档位)
编辑、添加绘图:


事实似乎确实如此:


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)

现在有9个。
所以,总而言之:添加高光似乎确实会使绘制的点增加…

两个代码都很好,您所说的额外点是什么意思?@Duck似乎新点会随着高光一起出现。例如:有3个点w/wt>5,cyl==8(在第一行中可见)。添加亮点后,在原来的3个点周围似乎有新的未高亮点。感谢您的帮助。你的例子很好,但我似乎看到了9点。我开始认为它正在创建新的点来突出显示,抖动会使旧点可见(通常会被覆盖)。你完全正确。确实有9个点有亮点。好像我数不清。相应地编辑了我的答案,并添加了说明该问题的图片。很抱歉
#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)