gpt4 book ai didi

r - 如何相对于彼此移动两个几何体的 x 轴位置

转载 作者:行者123 更新时间:2023-12-04 12:05:00 24 4
gpt4 key购买 nike

我有一个 ggplot阴谋。我需要相对于抖动点移动误差线。我的代码是:

data("cabbages", package = "MASS")

require("ggplot2")

pos_1 <- position_jitterdodge(
jitter.width = 0.25,
jitter.height = 0,
dodge.width = 0.9
)

gg <-
ggplot(data = cabbages,
aes(
x = Cult,
y = HeadWt,
colour = Cult,
fill = Cult
)) +

geom_jitter(alpha = 0.4, position = pos_1) +

stat_summary(fun.y = "mean", geom = "point", size = 3) +

stat_summary(fun.data = "mean_cl_normal",
geom = "errorbar",
width = 0.05,
lwd = 1,
fun.args = list(conf.int = 0.95)
) +

theme_bw()

print(gg)

目前的结果是:

enter image description here

我需要这样的东西:

enter image description here

最佳答案

您可以向 x 添加偏移量在 aes在每个 stat_summary ( aes(x = as.numeric(Cult) + 0.2) ):

ggplot(data = cabbages,
aes(x = Cult,
y = HeadWt,
colour = Cult,
fill = Cult)) +
geom_jitter(alpha = 0.4, position = pos_1) +
stat_summary(aes(x = as.numeric(Cult) + 0.2), fun.y = "mean", geom = "point", size = 3) +
stat_summary(aes(x = as.numeric(Cult) + 0.2), fun.data = "mean_cl_normal",
geom = "errorbar",
width = 0.05,
lwd = 1,
fun.args = list(conf.int = 0.95)) +
theme_bw()

enter image description here

关于r - 如何相对于彼此移动两个几何体的 x 轴位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42461993/

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