gpt4 book ai didi

r - 可以在 ggplot boxplot 中偏移抖动点吗

转载 作者:行者123 更新时间:2023-12-02 03:56:49 25 4
gpt4 key购买 nike

在 ggplot boxplot 中,很容易使用抖动来添加具有不同抖动程度的原始数据点。零抖动如下代码

dat <- data.frame(group=c('a', 'b', 'c'), values = runif(90))

ggplot(dat, aes(group, values)) +
geom_boxplot(outlier.size = 0) +
geom_jitter(position=position_jitter(width=0), aes(colour=group), alpha=0.7) +
ylim(0, 1) + stat_summary(fun.y=mean, shape=3, col='red', geom='point') +
opts(legend.position = "right") + ylab("values") + xlab("group")

产生下面的图。

是否可以使用零抖动但添加偏移量,使点位于一条线上,但向左移动框宽度的 25%?我尝试使用 geom_pointdodge 但这会产生抖动。 enter image description here

最佳答案

如果我们将组转换为数字,然后添加偏移量,您似乎会得到所需的输出。可能有一种更有效/高效的方法,但请尝试一下:

ggplot(dat, aes(group, values)) + 
geom_boxplot(outlier.size = 0) +
geom_point(aes(x = as.numeric(group) + .25, colour=group), alpha=0.7) +
ylim(0, 1) + stat_summary(fun.y=mean, shape=3, col='red', geom='point') +
opts(legend.position = "right") + ylab("values") + xlab("group")

enter image description here

关于r - 可以在 ggplot boxplot 中偏移抖动点吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8510003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com