{"id":1493,"date":"2023-08-31T13:25:31","date_gmt":"2023-08-31T05:25:31","guid":{"rendered":"https:\/\/stu.chcmu.asia\/?p=1493"},"modified":"2024-05-22T16:04:40","modified_gmt":"2024-05-22T08:04:40","slug":"barplot","status":"publish","type":"post","link":"https:\/\/stu.chcmu.asia\/index.php\/2023\/08\/31\/barplot\/","title":{"rendered":"barplot"},"content":{"rendered":"<pre><code class=\"language-r\">\n## \u6784\u5efa\u6570\u636e\ndata(iris)\ndat &lt;- iris[,1:4]\n\ndat &lt;- na.omit(dat) # \u53bb\u9664\u7f3a\u5931\u503c\n# \u8ba1\u7b97\u5e73\u5747\u503c\uff08mean\uff09\u4e0e\u6807\u51c6\u5dee\uff08sd\uff09\ndat &lt;- data.frame( var  = colnames(dat),\n                   mean = apply(dat, 2, mean ),\n                   sd   = apply(dat, 2, sd ) )\ndat\n\n# \u753b\u56fe\nlibrary(ggplot2)\nlibrary(ggsci)\nggplot(dat,aes(x = var, y = mean, fill = var ) ) +\n  geom_bar(stat     = &quot;identity&quot;,\n           position = position_dodge(),\n           width    = 0.6,\n           show.legend = F) +\n\n  geom_errorbar(aes(ymin = mean - sd,\n                    ymax = mean + sd ),\n                width = 0.2,\n                color=&quot;black&quot;, # \u8bef\u5dee\u7ebf\u989c\u8272\n                position=position_dodge(0.6) )+\n  # \u914d\u8272\u9009\u62e9\n  scale_fill_npg()+\n  # scale_fill_brewer(palette = &quot;Greens&quot;,direction = -1) +\n  # scale_fill_grey( start=1, end=0 )+\n  # scale_fill_discrete()+\n  # scale_fill_aaas()+\n  # scale_fill_hue()+\n  # scale_fill_manual(values = heat.colors( nrow(dat) ))+\n  # scale_fill_manual(values = terrain.colors( nrow(dat) ))+\n  theme_dark()+ # \u4e3b\u9898\n  labs(title=&quot;Barplot&quot;, x=&quot;var. of barplot&quot;, y=&quot;mean of barplot&quot;)+\n  theme(plot.title = element_text(hjust = 0.5))\n\n# \u4fdd\u5b58\u6570\u636e\n# ggsave(filename = &#039;barplot.png&#039;,width = 10, height = 8, units = &#039;cm&#039;,dpi = 500)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>## \u6784\u5efa\u6570\u636e data(iris) dat &lt;- iris[,1:4] dat &lt;- na.om [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":1499,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,31],"tags":[],"class_list":["post-1493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","category-statistics"],"_links":{"self":[{"href":"https:\/\/stu.chcmu.asia\/index.php\/wp-json\/wp\/v2\/posts\/1493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stu.chcmu.asia\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stu.chcmu.asia\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stu.chcmu.asia\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/stu.chcmu.asia\/index.php\/wp-json\/wp\/v2\/comments?post=1493"}],"version-history":[{"count":2,"href":"https:\/\/stu.chcmu.asia\/index.php\/wp-json\/wp\/v2\/posts\/1493\/revisions"}],"predecessor-version":[{"id":1498,"href":"https:\/\/stu.chcmu.asia\/index.php\/wp-json\/wp\/v2\/posts\/1493\/revisions\/1498"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/stu.chcmu.asia\/index.php\/wp-json\/wp\/v2\/media\/1499"}],"wp:attachment":[{"href":"https:\/\/stu.chcmu.asia\/index.php\/wp-json\/wp\/v2\/media?parent=1493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stu.chcmu.asia\/index.php\/wp-json\/wp\/v2\/categories?post=1493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stu.chcmu.asia\/index.php\/wp-json\/wp\/v2\/tags?post=1493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}