{"id":2025,"date":"2017-07-15T08:03:56","date_gmt":"2017-07-15T07:03:56","guid":{"rendered":"http:\/\/pcool.dyndns.org:8080\/statsbook\/?page_id=2025"},"modified":"2025-07-01T11:36:25","modified_gmt":"2025-07-01T10:36:25","slug":"bag-plot","status":"publish","type":"page","link":"https:\/\/pcool.dyndns.org\/index.php\/bag-plot\/","title":{"rendered":"Bag Plot"},"content":{"rendered":"\n<p>A bag plot is the <a href=\"https:\/\/pcool.dyndns.org\/index.php\/scatterplot\/\" data-type=\"page\" data-id=\"541\">scatterplot<\/a> variant of a <a href=\"https:\/\/pcool.dyndns.org\/index.php\/box-plot\/\" data-type=\"page\" data-id=\"501\">box and whisker plot<\/a> where &#8216;bags&#8217; correspond to the box in a box and whisker plot to illustrate outliers. To create a bag plot, use the\u00a0aplpack package<sup class='sup-ref-note' id='note-zotero-ref-p2025-r1-o1'><a class='sup-ref-note' href='#zotero-ref-p2025-r1'>1<\/a><\/sup>.<\/p>\n\n\n\n<p>As illustration the &#8216;mtcars&#8217; data frame that is part of base R is used. To show the first six observations (head) and the structure (str) of the data frame:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f00101\" class=\"has-inline-color\">head(mtcars)\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#1600f0\" class=\"has-inline-color\">                   mpg cyl disp  hp drat    wt  qsec vs am gear carb\nMazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4\nMazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4\nDatsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1\nHornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1\nHornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2\nValiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#f00101\" class=\"has-inline-color\">\nstr(mtcars)\n<\/mark><mark style=\"background-color:rgba(0, 0, 0, 0);color:#1600f0\" class=\"has-inline-color\">'data.frame':\t32 obs. of  11 variables:\n $ mpg : num  21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...\n $ cyl : num  6 6 4 6 8 6 8 4 4 6 ...\n $ disp: num  160 160 108 258 360 ...\n $ hp  : num  110 110 93 110 175 105 245 62 95 123 ...\n $ drat: num  3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...\n $ wt  : num  2.62 2.88 2.32 3.21 3.44 ...\n $ qsec: num  16.5 17 18.6 19.4 17 ...\n $ vs  : num  0 0 1 1 0 1 0 1 1 1 ...\n $ am  : num  1 1 1 0 0 0 0 0 0 0 ...\n $ gear: num  4 4 4 3 3 3 3 4 4 4 ...\n $ carb: num  4 4 1 1 2 1 4 2 2 4 ...<\/mark><\/em><\/code><\/pre>\n\n\n\n<p>To create a bag plot:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">library(aplpack)<\/span><\/em>\n<em><span style=\"color: #ff0000;\">bagplot(mtcars$wt, mtcars$hp, cex = 1, show.whiskers = FALSE, xlab = 'Car Mass', ylab = 'Horse Power', main = 'Bag Plot')<\/span><\/em><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"880\" src=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/bagplot-1024x880.png\" alt=\"\" class=\"wp-image-2802\" srcset=\"https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/bagplot-1024x880.png 1024w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/bagplot-300x258.png 300w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/bagplot-768x660.png 768w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/bagplot-1536x1319.png 1536w, https:\/\/pcool.dyndns.org\/wp-content\/uploads\/2025\/06\/bagplot.png 1630w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The inner dark-blue polygon is called the &#8216;bag&#8217; and contains 50% of the data (similar to the box in a box plot). The fence (not show) is an area three times the bag. All data points outside the fence are outliers and indicated in red. The &#8216;loop&#8217; (light-blue polygon) surrounds all data points that are not outliers (similar to the whiskers in a box plot).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A bag plot is the scatterplot variant of a box and whisker plot where &#8216;bags&#8217; correspond to the box in a box and whisker plot to illustrate outliers. To create a bag plot, use the\u00a0aplpack package. As illustration the &#8216;mtcars&#8217; data frame that is part of base R is used. To show the first six [&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-2025","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/2025","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=2025"}],"version-history":[{"count":2,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/2025\/revisions"}],"predecessor-version":[{"id":4701,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/2025\/revisions\/4701"}],"wp:attachment":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/media?parent=2025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}