{"id":1831,"date":"2017-01-23T20:37:57","date_gmt":"2017-01-23T20:37:57","guid":{"rendered":"http:\/\/pcool.dyndns.org:8080\/statsbook\/?page_id=1831"},"modified":"2025-07-01T08:54:35","modified_gmt":"2025-07-01T07:54:35","slug":"strip-plot","status":"publish","type":"page","link":"https:\/\/pcool.dyndns.org\/index.php\/strip-plot\/","title":{"rendered":"Strip Plot"},"content":{"rendered":"\n<p>A strip plot is a simple way of visualising numerical data in different categories. The plot shows the distribution of the data for each category as individual datapoints. The categories are displayed on the x-axis and the strips are vertical parallel to the y-axis. The plot can be created with the ggplot2<sup class='sup-ref-note' id='note-zotero-ref-p1831-r1-o1'><a class='sup-ref-note' href='#zotero-ref-p1831-r1'>1<\/a><\/sup> package.<\/p>\n\n\n\n<p>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 for this example 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 has-small-font-size\"><code><span style=\"color: #0000ff;\"><em><span style=\"color: #ff0000;\">strip<\/span>\n<\/em><\/span><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#1103ee\" 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 simple strip plot:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">library(ggplot2)\nggplot(strip, aes(x = MUA, y = Flexion)) + geom_jitter(position = position_jitter(0)) + <\/span><\/em>\n<em><span style=\"color: #ff0000;\">scale_x_discrete(limits = c('Pre','Post')) +<\/span><\/em>\n<em><span style=\"color: #ff0000;\">theme_bw()  <\/span><\/em><\/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\/strip-1024x1024.png\" alt=\"\" class=\"wp-image-3658\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip-1024x1024.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip-300x300.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip-150x150.png 150w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip-768x768.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip-1536x1536.png 1536w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip-2048x2048.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The <em><span style=\"color: #ff0000;\">scale_x_discrete(limits = c(&#8216;Pre&#8217;,&#8217;Post&#8217;) <\/span><\/em><span style=\"color: #ff0000;\"><span style=\"color: #000000;\">is required to plot &#8216;Pre&#8217; to the left of &#8216;Post&#8217; on the categorical x-axis.<\/span><\/span><\/p>\n\n\n\n<p>It is easy to display the groups in different colours. If the points overlap, it can become difficult to see how many data points there are. By introducing jitter, all data points can be visualised and the plot becomes similar to a swarm or <a href=\"https:\/\/pcool.dyndns.org\/index.php\/swam-plot\/\" data-type=\"page\" data-id=\"1833\">beeswarm plot<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">library(ggplot2)<\/span><\/em>\n<em><span style=\"color: #ff0000;\">ggplot(strip, aes(x = MUA, y = Flexion, color = MUA)) + geom_jitter(position = position_jitter(0.2)) +<\/span><\/em>\n<em><span style=\"color: #ff0000;\">scale_x_discrete(limits = c('Pre','Post')) + <\/span><\/em>\n<em><span style=\"color: #ff0000;\">scale_color_manual(values = c('red', 'blue')) + <\/span><\/em>\n<em><span style=\"color: #ff0000;\">theme_bw()<\/span><\/em> <em><span style=\"color: #ff0000;\">+<\/span><\/em>\n<em><span style=\"color: #ff0000;\">theme(legend.position = 'none')<\/span><\/em>\n<\/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\/strip2-1024x1024.png\" alt=\"\" class=\"wp-image-3663\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip2-1024x1024.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip2-300x300.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip2-150x150.png 150w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip2-768x768.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip2-1536x1536.png 1536w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip2-2048x2048.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Please note the <em><span style=\"color: #ff0000;\">color = MUA<\/span><\/em> maps the colour to the different categories. The colour is set manually with <span style=\"color: #ff0000;\"><em>scale_color_manual(values = c(&#8216;red&#8217;, &#8216;blue&#8217;))&nbsp;<\/em><span style=\"color: #000000;\">and the legend is switch off with&nbsp;<span style=\"color: #ff0000;\"><em>theme(legend.position = &#8216;none&#8217;)<\/em><\/span>. <\/span><\/span><\/p>\n\n\n\n<p>It is possible to combine a strip plot with a <a href=\"https:\/\/pcool.dyndns.org\/index.php\/box-plot\/\" data-type=\"page\" data-id=\"501\">box plot<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">library(ggplot2)<\/span><\/em>\n<em><span style=\"color: #ff0000;\">ggplot(strip, aes(x = MUA, y = Flexion, color = MUA)) + geom_boxplot(color = 'black') + <\/span><\/em>\n<em><span style=\"color: #ff0000;\">geom_jitter(position = position_jitter(0.2)) +<\/span><\/em>\n<em><span style=\"color: #ff0000;\">scale_x_discrete(limits = c('Pre','Post')) + <\/span><\/em>\n<em><span style=\"color: #ff0000;\">scale_color_manual(values = c('red', 'blue')) +<\/span><\/em>\n<em><span style=\"color: #ff0000;\">theme(legend.position = 'none') +<\/span><\/em>\n<em><span style=\"color: #ff0000;\">theme_bw()<\/span><\/em><\/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\/strip3-1024x1024.png\" alt=\"\" class=\"wp-image-3668\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip3-1024x1024.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip3-300x300.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip3-150x150.png 150w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip3-768x768.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip3-1536x1536.png 1536w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/strip3-2048x2048.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><span style=\"color: #000000;\">The <em><span style=\"color: #ff0000;\">geom_boxplot(color = &#8216;black&#8217;)<\/span><\/em> call should be before the geom_jitter call to plot the boxplot first and overlay this with the data points.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A strip plot is a simple way of visualising numerical data in different categories. The plot shows the distribution of the data for each category as individual datapoints. The categories are displayed on the x-axis and the strips are vertical parallel to the y-axis. The plot can be created with the ggplot2 package. Download and [&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-1831","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1831","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=1831"}],"version-history":[{"count":1,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1831\/revisions"}],"predecessor-version":[{"id":4651,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1831\/revisions\/4651"}],"wp:attachment":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/media?parent=1831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}