r - 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
#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)
编辑,添加情节:
解决方案
似乎确实是这样:
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)
#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 个。总而言之:添加高亮似乎确实会绘制额外的点......
推荐阅读
- javascript - 如何每次点击滑动到下一个元素?
- python - 我怎样才能让这段代码做它应该做的事情?
- ios - iOS PDFKit Swift 4,如何使在 PDFKIT 文本字段小部件中输入的文本全部大写?
- arrays - Excel 搜索数组公式不适用于数组的所有部分
- angular - 如何使用 Angular5 获取重定向 URL
- pdf - 如何使用 groovy 创建内存中的 pdf 文件并作为电子邮件附件发送
- cmd - 如何使用 cmd 从 .exe 文件中删除元数据
- python - 如何计算熊猫数据框中不同日期在同一时间(n小时窗口)进行的测量平均值?
- php - 属于返回类
- java - 由于索引超出范围,对“get”的调用总是无法索引