gpt4 book ai didi

r - 一种方式 - 带有 CI 的 R 中的 Anova 图

转载 作者:行者123 更新时间:2023-12-01 11:16:26 26 4
gpt4 key购买 nike

我执行了单向方差分析

mydat=structure(list(Price = c(1480000L, 1480000L, 1035000L, 1480000L, 
1465000L, 689000L, 611000L, 611000L, NA, 855000L, 855000L, NA,
1480000L, 1035000L, NA, 1465000L, 850000L), Regionname = structure(c(2L,
2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L
), .Label = c("Eastern Victoria", "Northern Metropolitan"), class = "factor")), .Names = c("Price",
"Regionname"), class = "data.frame", row.names = c(NA, -17L))

现在我尝试创建情节
require(ggplot2)

ggplot(mydat, aes(x = Regionname, y = Price)) +
geom_boxplot(fill = "grey80", colour = "blue") +
scale_x_discrete() + xlab("Regionname") +
ylab("Price")

但我对这个可视化完全不满意

如何获得像这张图片一样的情节

desired plot

最佳答案

那这个呢?

# make a simple regression first
s1 <- summary(lm(Price ~ Regionname + 0, mydat)) # note: w/o constant!

# of which you can create a model frame
m1 <- data.frame(coef=coef(s1)[1, 1], se=coef(s1)[1, 2], mn="Eastern Victoria")
m2 <- data.frame(coef=coef(s1)[2, 1], se=coef(s1)[2, 2], mn="Northern Metropolitan")
mf <- rbind(m1, m2)

i95 <- - qnorm((1 - .95) / 2) # significance 95%

library(ggplot2)
ggplot(mf, aes(color=mn)) +
geom_pointrange(aes(x=mn, y=coef, ymin=coef - se*i95, ymax=coef + se*i95), shape=0) +
geom_errorbar(aes(x=mn, ymin=coef - se*i95, ymax=coef + se*i95), width=.2) +
geom_line(aes(y=coef, x=mn, group=1)) +
scale_color_manual(values=rep("dark red", 2)) +
labs(x="Regionname", y="Price") +
guides(color=FALSE) +
theme_bw()

产量

enter image description here

关于r - 一种方式 - 带有 CI 的 R 中的 Anova 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50435836/

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