{"id":5885,"date":"2016-03-24T00:27:23","date_gmt":"2016-03-23T23:27:23","guid":{"rendered":"http:\/\/emilkirkegaard.dk\/en\/?p=5885"},"modified":"2016-03-24T00:29:15","modified_gmt":"2016-03-23T23:29:15","slug":"kirkegaard-plot-contingency-table-with-ggplot2","status":"publish","type":"post","link":"https:\/\/emilkirkegaard.dk\/en\/2016\/03\/kirkegaard-plot-contingency-table-with-ggplot2\/","title":{"rendered":"kirkegaard: Plot contingency table with ggplot2"},"content":{"rendered":"<p><em>This is a post in the on-going series about stuff in my package: <a href=\"https:\/\/github.com\/Deleetdk\/kirkegaard\">kirkegaard <\/a>[I&#8217;m not egocentric but since there is no central theme about the functions in the package other than I made and use them, there is nothing else to call it.]<\/em><\/p>\n<p>I figure it should be easy to find someone who wrote a ready-made function to plot contingency matrices with ggplot2. Not so apparently!<\/p>\n<p>However, it is a relatively simple matter. So here&#8217;s one:<\/p>\n<p>Features:<\/p>\n<ul>\n<li>Easily plot a decent contingency table with ggplot2. Just input the datafile and the names of the two variables.<\/li>\n<li>Can also calculate marginal values, which is to say that we set either all rows or columns to be 1.<\/li>\n<li>Automatically sets the axis labels to the names you used, which is often enough.<\/li>\n<\/ul>\n<pre>library(devtools); install_github(\"deleetdk\/kirkegaard\"); library(kirkegaard)\r\nGG_contingency_table(mpg, \"drv\", \"cyl\")<\/pre>\n<p><a href=\"http:\/\/emilkirkegaard.dk\/en\/wp-content\/uploads\/contin_table_2.png\" rel=\"attachment wp-att-5886\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-5886\" src=\"http:\/\/emilkirkegaard.dk\/en\/wp-content\/uploads\/contin_table_2-300x158.png\" alt=\"contin_table_2\" width=\"300\" height=\"158\" \/><\/a><\/p>\n<pre>GG_contingency_table(mpg, \"drv\", \"cyl\", margin = 1)<\/pre>\n<p><a href=\"http:\/\/emilkirkegaard.dk\/en\/wp-content\/uploads\/contin_table_1.png\" rel=\"attachment wp-att-5887\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-5887\" src=\"http:\/\/emilkirkegaard.dk\/en\/wp-content\/uploads\/contin_table_1-300x158.png\" alt=\"contin_table_1\" width=\"300\" height=\"158\" \/><\/a><\/p>\n<pre>GG_contingency_table(mpg, \"drv\", \"cyl\", margin = 2)<\/pre>\n<p><a href=\"http:\/\/emilkirkegaard.dk\/en\/wp-content\/uploads\/contin_table_2.png\" rel=\"attachment wp-att-5886\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-5886\" src=\"http:\/\/emilkirkegaard.dk\/en\/wp-content\/uploads\/contin_table_2-300x158.png\" alt=\"contin_table_2\" width=\"300\" height=\"158\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a post in the on-going series about stuff in my package: kirkegaard [I&#8217;m not egocentric but since there is no central theme about the functions in the package other than I made and use them, there is nothing else to call it.] I figure it should be easy to find someone who wrote [&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":[2320,2220,2321,1979],"class_list":["post-5885","post","type-post","status-publish","format-standard","hentry","category-programming","tag-contingency-table","tag-ggplot2","tag-plot","tag-r","entry"],"_links":{"self":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/5885","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=5885"}],"version-history":[{"count":3,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/5885\/revisions"}],"predecessor-version":[{"id":5891,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/5885\/revisions\/5891"}],"wp:attachment":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/media?parent=5885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/categories?post=5885"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/tags?post=5885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}