多因素方差分析
library(multcompView)
library(stats)
library(tidyverse)
library(ggsci)

data2 <- ToothGrowth
data2$dose = as.factor(data2$dose)

anova <- aov(len ~ supp*dose, data = data2) #two way anova
summary(anova) #represents ANOVA

tukey <- TukeyHSD(anova)

group_lettering <- multcompLetters4(anova, tukey) #
group_lettering
group_lettering2 <- data.frame(group_lettering$`supp:dose`$Letters)
group_lettering2

mean_data2 <- data2 %>% 
  group_by(supp, dose) %>% 
  summarise(len_mean=mean(len), sd = sd(len)) %>%
  arrange(desc(len_mean))

mean_data2$group_lettering <- group_lettering2$group_lettering..supp.dose..Letters


ggplot(mean_data2,aes(x = dose, y = len_mean,group=supp))+
  geom_bar(position=position_dodge(0.9),stat = "identity", aes(fill = supp), 
           show.legend = TRUE)

ggplot(mean_data2, aes(x = dose, y = len_mean,group=supp))+
  geom_bar(position=position_dodge(0.9),stat = "identity",
           aes(fill = supp),show.legend = TRUE) +
  geom_errorbar(aes(ymin = len_mean-sd, ymax=len_mean+sd),width = 0.1,
                position=position_dodge(0.9))

ggplot(mean_data2, aes(x = dose, y = len_mean,group=supp))+
  geom_bar(position=position_dodge(0.9),stat = "identity",
           aes(fill = supp), show.legend = TRUE) +
  geom_errorbar(aes(ymin = len_mean-sd, ymax=len_mean+sd),
                width = 0.1, position=position_dodge(0.9))+
  geom_text(aes(label = group_lettering, y = len_mean + sd),
            vjust=-0.4,position=position_dodge(0.9))


ggplot(mean_data2, aes(x = dose, y = len_mean,group=supp))+
  geom_bar(position=position_dodge(0.9),stat = "identity",
           aes(fill = supp), show.legend = TRUE) +
  geom_errorbar(aes(ymin = len_mean-sd, ymax=len_mean+sd),
                width = 0.1, position=position_dodge(0.9)) + 
  geom_text(aes(label = group_lettering, y = len_mean + sd),
            vjust=-0.4, position=position_dodge(0.9)) +
  scale_y_continuous(expand = expansion(0),limits = c(0,35),
                     breaks = seq(0,35,5))+
  labs(x=NULL,y=NULL)+
  theme_minimal()+
  theme(
    plot.margin = unit(c(0.2,0.2,0.2,0.2), "cm"),
    panel.background = element_blank(),
    axis.line = element_line(color = "black"),
    axis.title = element_text(size = 10, color = "black",face = "bold"),
    axis.text = element_text(size = 10,color = "black"),
    axis.text.x = element_text(margin=margin(t =3)),
    axis.text.y = element_text(size = 10),
    axis.title.y = element_text(margin = margin(r = 10)),
    axis.ticks.x = element_blank())+
  # scale_fill_jco()
scale_fill_jama()
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇