{"id":437,"date":"2022-04-18T10:29:24","date_gmt":"2022-04-18T02:29:24","guid":{"rendered":"https:\/\/linguopeng.top\/?p=437"},"modified":"2022-04-18T10:29:25","modified_gmt":"2022-04-18T02:29:25","slug":"2%e5%9b%a0%e7%b4%a0%e4%b8%8e%e4%b8%89%e5%9b%a0%e7%b4%a0%e6%96%b9%e5%b7%ae%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/linguopeng.top\/?p=437","title":{"rendered":"2\u56e0\u7d20\u4e0e\u4e09\u56e0\u7d20\u65b9\u5dee\u5206\u6790"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>> library(multcompView)\r\n> library(stats)\r\n> library(tidyverse)\r\n> library(ggsci)\r\n> \r\n> data2 &lt;- ToothGrowth\r\n> data2$dose = as.factor(data2$dose)\r\n> \r\n> anova &lt;- aov(len ~ supp*dose, data = data2) #two way anova\r\n> summary(anova) #represents ANOVA\r\n            Df Sum Sq Mean Sq F value   Pr(>F)    \r\nsupp         1  205.4   205.4  15.572 0.000231 ***\r\ndose         2 2426.4  1213.2  92.000  &lt; 2e-16 ***\r\nsupp:dose    2  108.3    54.2   4.107 0.021860 *  \r\nResiduals   54  712.1    13.2                     \r\n---\r\nSignif. codes:  0 \u2018***\u2019 0.001 \u2018**\u2019 0.01 \u2018*\u2019 0.05 \u2018.\u2019 0.1 \u2018 \u2019 1\r\n> \r\n> tukey &lt;- TukeyHSD(anova)\r\n> \r\n> group_lettering &lt;- multcompLetters4(anova, tukey) #\r\n> group_lettering\r\n$supp\r\n OJ  VC \r\n\"a\" \"b\" \r\n\r\n$dose\r\n  2   1 0.5 \r\n\"a\" \"b\" \"c\" \r\n\r\n$`supp:dose`\r\n  VC:2   OJ:2   OJ:1   VC:1 OJ:0.5 VC:0.5 \r\n   \"a\"    \"a\"    \"a\"    \"b\"    \"b\"    \"c\" \r\n\r\n> group_lettering2 &lt;- data.frame(group_lettering$`supp:dose`$Letters)\r\n> group_lettering2\r\n       group_lettering..supp.dose..Letters\r\nVC:2                                     a\r\nOJ:2                                     a\r\nOJ:1                                     a\r\nVC:1                                     b\r\nOJ:0.5                                   b\r\nVC:0.5                                   c\r\n> \r\n> mean_data2 &lt;- data2 %>% \r\n+   group_by(supp, dose) %>% \r\n+   summarise(len_mean=mean(len), sd = sd(len)) %>%\r\n+   arrange(desc(len_mean))\r\n`summarise()` has grouped output by 'supp'. You can override using\r\nthe `.groups` argument.\r\n> \r\n> mean_data2$group_lettering &lt;- group_lettering2$group_lettering..supp.dose..Letters\r\n> \r\n> \r\n> ggplot(mean_data2,aes(x = dose, y = len_mean,group=supp))+\r\n+   geom_bar(position=position_dodge(0.9),stat = \"identity\", aes(fill = supp), \r\n+            show.legend = TRUE)\r\n> \r\n> ggplot(mean_data2, aes(x = dose, y = len_mean,group=supp))+\r\n+   geom_bar(position=position_dodge(0.9),stat = \"identity\",\r\n+            aes(fill = supp),show.legend = TRUE) +\r\n+   geom_errorbar(aes(ymin = len_mean-sd, ymax=len_mean+sd),width = 0.1,\r\n+                 position=position_dodge(0.9))\r\n> \r\n> ggplot(mean_data2, aes(x = dose, y = len_mean,group=supp))+\r\n+   geom_bar(position=position_dodge(0.9),stat = \"identity\",\r\n+            aes(fill = supp), show.legend = TRUE) +\r\n+   geom_errorbar(aes(ymin = len_mean-sd, ymax=len_mean+sd),\r\n+                 width = 0.1, position=position_dodge(0.9))+\r\n+   geom_text(aes(label = group_lettering, y = len_mean + sd),\r\n+             vjust=-0.4,position=position_dodge(0.9))\r\n> \r\n> \r\n> ggplot(mean_data2, aes(x = dose, y = len_mean,group=supp))+\r\n+   geom_bar(position=position_dodge(0.9),stat = \"identity\",\r\n+            aes(fill = supp), show.legend = TRUE) +\r\n+   geom_errorbar(aes(ymin = len_mean-sd, ymax=len_mean+sd),\r\n+                 width = 0.1, position=position_dodge(0.9)) + \r\n+   geom_text(aes(label = group_lettering, y = len_mean + sd),\r\n+             vjust=-0.4, position=position_dodge(0.9)) +\r\n+   scale_y_continuous(expand = expansion(0),limits = c(0,35),\r\n+                      breaks = seq(0,35,5))+\r\n+   labs(x=NULL,y=NULL)+\r\n+   theme_minimal()+\r\n+   theme(\r\n+     plot.margin = unit(c(0.2,0.2,0.2,0.2), \"cm\"),\r\n+     panel.background = element_blank(),\r\n+     axis.line = element_line(color = \"black\"),\r\n+     axis.title = element_text(size = 10, color = \"black\",face = \"bold\"),\r\n+     axis.text = element_text(size = 10,color = \"black\"),\r\n+     axis.text.x = element_text(margin=margin(t =3)),\r\n+     axis.text.y = element_text(size = 10),\r\n+     axis.title.y = element_text(margin = margin(r = 10)),\r\n+     axis.ticks.x = element_blank())+\r\n+   scale_fill_jco()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/linguopeng.top\/wp-content\/uploads\/2022\/04\/Rplot.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"592\" height=\"489\" data-original=\"https:\/\/linguopeng.top\/wp-content\/uploads\/2022\/04\/Rplot.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-438\"\/><\/div><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>> library(tidyverse)\r\n> library(ggthemes)\r\n> library(multcompView)\r\n> library(egg)\r\n> df &lt;- read_tsv(\"co2.xls\")\r\nRows: 84 Columns: 5                                                                                   \r\n\u2500\u2500 Column specification \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\nDelimiter: \"\\t\"\r\nchr (3): Plant, Type, Treatment\r\ndbl (2): conc, uptake\r\n\r\n\u2139 Use `spec()` to retrieve the full column specification for this data.\r\n\u2139 Specify the column types or set `show_col_types = FALSE` to quiet this message.\r\n> anova &lt;- aov(uptake ~ factor(conc)*Type*Treatment, data = df)\r\n> summary(anova)\r\n                            Df Sum Sq Mean Sq F value   Pr(>F)    \r\nfactor(conc)                 6   4069     678  80.548  &lt; 2e-16 ***\r\nType                         1   3366    3366 399.758  &lt; 2e-16 ***\r\nTreatment                    1    988     988 117.368 2.32e-15 ***\r\nfactor(conc):Type            6    374      62   7.412 7.24e-06 ***\r\nfactor(conc):Treatment       6    101      17   1.999   0.0811 .  \r\nType:Treatment               1    226     226  26.812 3.15e-06 ***\r\nfactor(conc):Type:Treatment  6    112      19   2.216   0.0547 .  \r\nResiduals                   56    471       8                     \r\n---\r\nSignif. codes:  0 \u2018***\u2019 0.001 \u2018**\u2019 0.01 \u2018*\u2019 0.05 \u2018.\u2019 0.1 \u2018 \u2019 1\r\n> Tukey &lt;- TukeyHSD(anova)\r\n> cld &lt;- multcompLetters4(anova, Tukey)\r\n> dt &lt;- group_by(CO2, conc, Type, Treatment) %>%\r\n+   summarise(uptake_mean=mean(uptake), sd=sd(uptake)) %>%\r\n+   arrange(desc(uptake_mean))\r\n`summarise()` has grouped output by 'conc', 'Type'. You can\r\noverride using the `.groups` argument.\r\n> cld &lt;- as.data.frame.list(cld$`factor(conc):Type:Treatment`)\r\n> dt$Tukey &lt;- cld$Letters\r\n> ggplot(dt,aes(x = factor(conc), y = uptake_mean, fill = Type:Treatment)) +\r\n+   geom_bar(stat = \"identity\", position = \"dodge\") +\r\n+   geom_errorbar(aes(ymax = uptake_mean + sd, ymin = uptake_mean - sd),\r\n+                 position = position_dodge(0.9), width = 0.25, color = \"Gray25\") +\r\n+   xlab(expression(CO&#91;2]~Concentration~'('~mL~L^-1~')')) +\r\n+   ylab(expression(CO&#91;2]~Uptake~'('~\u00b5mol~m^2~s^-1~')')) +\r\n+   scale_fill_brewer(palette = \"Greens\") +\r\n+   theme_few()\r\n> ggplot(dt, aes(x = factor(conc), y = uptake_mean, fill = Treatment)) +\r\n+   geom_bar(stat = \"identity\", position = \"dodge\") +\r\n+   geom_errorbar(aes(ymax = uptake_mean + sd, ymin = uptake_mean - sd),\r\n+                 position = position_dodge(0.9), width = 0.25, color = \"Gray25\") +\r\n+   xlab(expression(CO&#91;2]~Concentration~'('~mL~L^-1~')')) +\r\n+   ylab(expression(CO&#91;2]~Uptake~'('~\u00b5mol~m^2~s^-1~')')) +\r\n+   scale_fill_brewer(palette = \"Greens\") +\r\n+   theme_few() +\r\n+   facet_grid(.~Type, labeller = label_both)\r\n> \r\n> p &lt;- ggplot(dt, aes(x = factor(conc), y = uptake_mean, fill = Treatment)) +\r\n+   geom_bar(stat = \"identity\", position = \"dodge\") +\r\n+   geom_errorbar(aes(ymax = uptake_mean + sd, ymin = uptake_mean - sd),\r\n+                 position = position_dodge(0.9), width = 0.25, color = \"Gray25\") +\r\n+   xlab(expression(CO&#91;2]~Concentration~'('~mL~L^-1~')')) +\r\n+   ylab(expression(CO&#91;2]~Uptake~'('~\u00b5mol~m^2~s^-1~')')) +\r\n+   theme_few() +\r\n+   theme(legend.position = c(0.95,0.98),legend.justification = c(1, 1),\r\n+         legend.title = element_blank(),\r\n+         axis.text=element_text(color=\"black\"),\r\n+         axis.title = element_text(color=\"black\")) +\r\n+   scale_fill_manual(values = c(\"#C1D5A5\", \"#84A17C\")) +\r\n+   scale_y_continuous(expand = expansion(0),limits = c(0,50),breaks = seq(0,50,5))+\r\n+   facet_grid(.~Type, labeller = label_both) +\r\n+   geom_text(aes(label=Tukey, y = uptake_mean + sd + 2), size = 3, color = \"Gray25\",\r\n+             show.legend = FALSE,position = position_dodge(0.9))\r\n> \r\n> tag_facet(p, fontface = 1, tag_pool = c(\"(a) Quebec\",\r\n+                                         \"(b) Mississipi\"),\r\n+           open = NULL, close = NULL, hjust = -0.05)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/linguopeng.top\/wp-content\/uploads\/2022\/04\/Rplot01.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"592\" height=\"489\" data-original=\"https:\/\/linguopeng.top\/wp-content\/uploads\/2022\/04\/Rplot01.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-439\"\/><\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-437","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/437","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=437"}],"version-history":[{"count":1,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/437\/revisions"}],"predecessor-version":[{"id":440,"href":"https:\/\/linguopeng.top\/index.php?rest_route=\/wp\/v2\/posts\/437\/revisions\/440"}],"wp:attachment":[{"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linguopeng.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}