分割蜂群-使用geom_quasirandom方法=笑脸的奇特分布 [英] Split beeswarm - peculiar distribution with geom_quasirandom method = smiley
本文介绍了分割蜂群-使用geom_quasirandom方法=笑脸的奇特分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是该问题的后续措施:
为什么随着样本量的增加会发生这种情况?
解决方案
它与分发点的方法有关.更改此内容:
p<-ggplot(my_dat,aes(x,y,color = m))+geom_quasirandom(method ='pseudorandom')#而不是'smiley'p<-ggplot_build(p)p $ data [[1]]<-p $ data [[1]]%&%mutate(x = case_when(colour ==#00BFC4"〜面板+ abs(PANEL-x),正确〜面板-abs(面板-x)))情节(ggplot_gtable(p))
This is a follow up on the question: Split beeswarm plot
I ask it as a new question, because my first question was sufficiently answered. But with my real data, there was suddenly a weird behaviour that I don't understand.
With the previous data frame
my_dat <- data.frame(x = 'x', m = rep(c('a','b'),100), y = rnorm(200))
the suggested solution works nice. But when I boost up my data a bit (simply increasing the sample size!), the plot becomes weird:
my_dat <- data.frame(x = 'x', m = letters[1:2], y = sample(0:100, 2000, replace = T), stringsAsFactors = F)
require(ggplot2)
require(ggbeeswarm)
require(dplyr)
p <- ggplot(my_dat, aes(x,y,color=m))+ ## this is copy/paste from @Jimbou's great idea.
geom_quasirandom(method = 'smiley')
p <- ggplot_build(p)
p$data[[1]] <- p$data[[1]] %>%
mutate(x=case_when(
colour=="#00BFC4" ~ PANEL + abs(PANEL - x),
TRUE ~ PANEL - abs(PANEL - x))
)
plot(ggplot_gtable(p))
Why does this happen with increased sample size??
解决方案
It has to do with the method to distribute the points. Changing this:
p <- ggplot(my_dat, aes(x,y,color=m))+
geom_quasirandom(method = 'pseudorandom') #instead of 'smiley'
p <- ggplot_build(p)
p$data[[1]] <- p$data[[1]] %>%
mutate(x=case_when(
colour=="#00BFC4" ~ PANEL + abs(PANEL - x),
TRUE ~ PANEL - abs(PANEL - x))
)
plot(ggplot_gtable(p))
这篇关于分割蜂群-使用geom_quasirandom方法=笑脸的奇特分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文