单向 - 带有CI的R中的Anova情节

时间:2018-05-20 14:28:16

标签: r ggplot2

我执行单向anova

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

2 个答案:

答案 0 :(得分:3)

这个怎么样?

$lang=en
$contentCatalog=mystoreContentCatalog

UPDATE ContentCatalog;id[unique=true];name[lang=$lang]
;$contentCatalog;"mystore Content Catalog"

<强> 产量

enter image description here

答案 1 :(得分:2)

我希望这有帮助,给定的数据不包含有关第三组&#39;西部大城市的任何信息,因此仅针对两组绘制:

   library(tidyverse)
    mydat %>% 
        group_by(Regionname) %>% 
    summarise( mean = mean(Price, na.rm=TRUE),#you can choose a different summay stats here like median etc.
                           sd = sd(Price, na.rm=TRUE),
                           n = n(),
                           se=sd/sqrt(n),
                           ci = qt(0.975, df=n-1)*se) %>% ##I have taken 95% Confidence interval, you can decide yourself
        ggplot(aes(x=Regionname, y=mean, group = factor(1))) +
        geom_line() + ##connecting lines between the error bars
        geom_point() + 
        geom_errorbar(aes(ymin=mean-ci, ymax=mean+ci), width=.1) + ##Errorbar instead of boxplot as per your requirement
        ggtitle("Figure Mean Score by Regionname")

enter image description here