{"id":5685,"date":"2015-12-09T13:30:13","date_gmt":"2015-12-09T12:30:13","guid":{"rendered":"http:\/\/emilkirkegaard.dk\/en\/?p=5685"},"modified":"2015-12-09T13:30:13","modified_gmt":"2015-12-09T12:30:13","slug":"kirkegaard-gg_group_means-easy-plotting-of-group-means-using-ggplot2","status":"publish","type":"post","link":"https:\/\/emilkirkegaard.dk\/en\/2015\/12\/kirkegaard-gg_group_means-easy-plotting-of-group-means-using-ggplot2\/","title":{"rendered":"kirkegaard: GG_group_means(), easy plotting of group means using ggplot2"},"content":{"rendered":"<p>Do you find yourself in need of making nice ggplot2 plots for group means over and over again? Are you tired of (re-)writing <a href=\"http:\/\/www.cookbook-r.com\/Graphs\/Plotting_means_and_error_bars_%28ggplot2%29\/\">big chunks of code<\/a> for something that should be easy? Here&#8217;s a solution. First install the package from Github using devtools:<\/p>\n<pre id=\"rstudio_console_output\" class=\"GEM3DMTCFGB\" tabindex=\"0\"><span class=\"GEM3DMTCLFB ace_keyword\">library(devtools)\r\ninstall_github(\"deleetdk\/kirkegaard\")<\/span><\/pre>\n<p>Then we plot:<\/p>\n<pre>library(kirkegaard)\r\nGG_group_means(iris, \"Sepal.Length\", \"Species\")<\/pre>\n<p><a href=\"http:\/\/emilkirkegaard.dk\/en\/wp-content\/uploads\/gg_group1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-5686\" src=\"http:\/\/emilkirkegaard.dk\/en\/wp-content\/uploads\/gg_group1-1024x528.png\" alt=\"gg_group1\" width=\"720\" height=\"371\" \/><\/a><\/p>\n<p>But what if we don&#8217;t like bar plots? Maybe because values of 0 don&#8217;t make sense:<\/p>\n<pre>GG_group_means(iris, \"Sepal.Length\", \"Species\", type = \"point\")<\/pre>\n<p><a href=\"http:\/\/emilkirkegaard.dk\/en\/wp-content\/uploads\/gg_group2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-5687\" src=\"http:\/\/emilkirkegaard.dk\/en\/wp-content\/uploads\/gg_group2-1024x528.png\" alt=\"gg_group2\" width=\"720\" height=\"371\" \/><\/a><\/p>\n<p>But what if we think that using just one point obscures the internal variation in groups? Let&#8217;s use all the points:<\/p>\n<pre>GG_group_means(iris, \"Sepal.Length\", \"Species\", type = \"points\")<\/pre>\n<p><a href=\"http:\/\/emilkirkegaard.dk\/en\/wp-content\/uploads\/gg_group3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-5688\" src=\"http:\/\/emilkirkegaard.dk\/en\/wp-content\/uploads\/gg_group3-1024x528.png\" alt=\"gg_group3\" width=\"720\" height=\"371\" \/><\/a><\/p>\n<p>But what if we really, really want to be sure of getting the right means? Maybe use a 99.9999% confidence interval:<\/p>\n<pre>GG_group_means(iris, \"Sepal.Length\", \"Species\", type = \"points\", CI = .999999)<\/pre>\n<p><a href=\"http:\/\/emilkirkegaard.dk\/en\/wp-content\/uploads\/gg_group4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-5689\" src=\"http:\/\/emilkirkegaard.dk\/en\/wp-content\/uploads\/gg_group4-1024x528.png\" alt=\"gg_group4\" width=\"720\" height=\"371\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Do you find yourself in need of making nice ggplot2 plots for group means over and over again? Are you tired of (re-)writing big chunks of code for something that should be easy? Here&#8217;s a solution. First install the package from Github using devtools: library(devtools) install_github(&#8220;deleetdk\/kirkegaard&#8221;) Then we plot: library(kirkegaard) GG_group_means(iris, &#8220;Sepal.Length&#8221;, &#8220;Species&#8221;) But what [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2089],"tags":[2220,1979],"class_list":["post-5685","post","type-post","status-publish","format-standard","hentry","category-programming","tag-ggplot2","tag-r","entry"],"_links":{"self":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/5685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/comments?post=5685"}],"version-history":[{"count":1,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/5685\/revisions"}],"predecessor-version":[{"id":5690,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/5685\/revisions\/5690"}],"wp:attachment":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/media?parent=5685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/categories?post=5685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/tags?post=5685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}