{"id":1833,"date":"2017-01-23T20:38:32","date_gmt":"2017-01-23T20:38:32","guid":{"rendered":"http:\/\/pcool.dyndns.org:8080\/statsbook\/?page_id=1833"},"modified":"2025-07-01T09:13:37","modified_gmt":"2025-07-01T08:13:37","slug":"swam-plot","status":"publish","type":"page","link":"https:\/\/pcool.dyndns.org\/index.php\/swam-plot\/","title":{"rendered":"Swarm Plot"},"content":{"rendered":"\n<p>Rather than using the ggplot2<sup class='sup-ref-note' id='note-zotero-ref-p1833-r1-o1'><a class='sup-ref-note' href='#zotero-ref-p1833-r1'>1<\/a><\/sup>, it is much easier to make swarm plots using the swarmplot package<sup class='sup-ref-note' id='note-zotero-ref-p1833-r2-o1'><a class='sup-ref-note' href='#zotero-ref-p1833-r2'>2<\/a><\/sup>. The plot is similar to a <a href=\"https:\/\/pcool.dyndns.org\/index.php\/strip-plot\/\" data-type=\"page\" data-id=\"1831\">strip plot<\/a> with jitter, but the graphical presentation is more elegant.<\/p>\n\n\n\n<p>For this example, download and open the <a href=\"https:\/\/pcool.dyndns.org:\/wp-content\/data_files\/strip.rda\" target=\"_blank\" rel=\"noreferrer noopener\">strip.rda<\/a> dataset and open it in R. The data set contains the maximum flexion in 20 patients before and after a manipulation under anaesthesia. The data can be shown by:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f80606\" class=\"has-inline-color\">strip\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#1b05f7\" class=\"has-inline-color\">   Flexion  MUA\n1       94  Pre\n2       95  Pre\n.....\n.....\n39     113 Post\n40      86 Post<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>To create a swarm plot:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>library(beeswarm)<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>beeswarm(Flexion ~ MUA, data = strip, col = 3:2, pch = 16 )<\/em><\/span>\n<a href=\"http:\/\/pcool.dyndns.org:8080\/statsbook\/wp-content\/uploads\/swarm1.png\"><\/a><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/swarm1-1024x1024.png\" alt=\"\" class=\"wp-image-3792\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/swarm1-1024x1024.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/swarm1-300x300.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/swarm1-150x150.png 150w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/swarm1-768x768.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/swarm1-1536x1536.png 1536w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/swarm1-2048x2048.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>For further option, please refer to the package manual<sup class='sup-ref-note' id='note-zotero-ref-p1833-r3-o1'><a class='sup-ref-note' href='#zotero-ref-p1833-r3'>3<\/a><\/sup> manual.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rather than using the ggplot2, it is much easier to make swarm plots using the swarmplot package. The plot is similar to a strip plot with jitter, but the graphical presentation is more elegant. For this example, download and open the strip.rda dataset and open it in R. The data set contains the maximum flexion [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"footnotes":""},"class_list":["post-1833","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/comments?post=1833"}],"version-history":[{"count":1,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1833\/revisions"}],"predecessor-version":[{"id":4653,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1833\/revisions\/4653"}],"wp:attachment":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/media?parent=1833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}