{"id":8319,"date":"2018-12-31T01:29:02","date_gmt":"2018-12-30T23:29:02","guid":{"rendered":"https:\/\/www.datanovia.com\/en\/?post_type=dt_lessons&#038;p=8319"},"modified":"2019-11-17T23:06:13","modified_gmt":"2019-11-17T21:06:13","slug":"ggplot-stripchart","status":"publish","type":"dt_lessons","link":"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/","title":{"rendered":"GGPlot Stripchart"},"content":{"rendered":"<div id=\"rdoc\">\n<p><strong>Stripcharts<\/strong> are also known as one dimensional scatter plots. These plots are suitable compared to box plots when sample sizes are small.<\/p>\n<p>This article describes how to create and customize <strong>Stripcharts<\/strong> using the <strong>ggplot2<\/strong> R package.<\/p>\n<p>Contents:<\/p>\n<div id=\"TOC\">\n<ul>\n<li><a href=\"#key-r-functions\">Key R functions<\/a><\/li>\n<li><a href=\"#data-preparation\">Data preparation<\/a><\/li>\n<li><a href=\"#loading-required-r-package\">Loading required R package<\/a><\/li>\n<li><a href=\"#basic-stripcharts\">Basic stripcharts<\/a><\/li>\n<li><a href=\"#combine-with-box-plots-and-violin-plots\">Combine with box plots and violin plots<\/a><\/li>\n<li><a href=\"#create-a-stripchart-with-multiple-groups\">Create a stripchart with multiple groups<\/a><\/li>\n<li><a href=\"#conclusion\">Conclusion<\/a><\/li>\n<\/ul>\n<\/div>\n<div class='dt-sc-hr-invisible-medium  '><\/div>\n<div class='dt-sc-ico-content type1'><div class='custom-icon' ><a href='https:\/\/www.datanovia.com\/en\/product\/ggplot2-essentials-for-great-data-visualization-in-r\/' target='_blank'><span class='fa fa-book'><\/span><\/a><\/div><h4><a href='https:\/\/www.datanovia.com\/en\/product\/ggplot2-essentials-for-great-data-visualization-in-r\/' target='_blank'> Related Book <\/a><\/h4>GGPlot2 Essentials for Great Data Visualization in R<\/div>\n<div class='dt-sc-hr-invisible-medium  '><\/div>\n<div id=\"key-r-functions\" class=\"section level2\">\n<h2>Key R functions<\/h2>\n<ul>\n<li>Key function: <code>geom_jitter()<\/code><\/li>\n<li>key arguments: <code>color<\/code>, <code>fill<\/code>, <code>size<\/code>, <code>shape<\/code>. Changes points color, fill, size and shape<\/li>\n<\/ul>\n<\/div>\n<div id=\"data-preparation\" class=\"section level2\">\n<h2>Data preparation<\/h2>\n<ul>\n<li>Demo dataset: <code>ToothGrowth<\/code>\n<ul>\n<li>Continuous variable: <code>len<\/code> (tooth length). Used on y-axis<\/li>\n<li>Grouping variable: <code>dose<\/code> (dose levels of vitamin C: 0.5, 1, and 2 mg\/day). Used on x-axis.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>First, convert the variable <code>dose<\/code> from a numeric to a discrete factor variable:<\/p>\n<pre class=\"r\"><code>data(\"ToothGrowth\")\r\nToothGrowth$dose &lt;- as.factor(ToothGrowth$dose)\r\nhead(ToothGrowth, 3)<\/code><\/pre>\n<pre><code>##    len supp dose\r\n## 1  4.2   VC  0.5\r\n## 2 11.5   VC  0.5\r\n## 3  7.3   VC  0.5<\/code><\/pre>\n<\/div>\n<div id=\"loading-required-r-package\" class=\"section level2\">\n<h2>Loading required R package<\/h2>\n<p>Load the ggplot2 package and set the default theme to <code>theme_classic()<\/code> with the legend at the top of the plot:<\/p>\n<pre class=\"r\"><code>library(ggplot2)\r\ntheme_set(\r\n  theme_classic() +\r\n    theme(legend.position = \"top\")\r\n  )<\/code><\/pre>\n<\/div>\n<div id=\"basic-stripcharts\" class=\"section level2\">\n<h2>Basic stripcharts<\/h2>\n<p>We start by initiating a plot named <code>e<\/code>, then we\u2019ll add layers. The following R code creates stripcharts combined with summary statistics (mean +\/- SD), boxplots and violin plots.<\/p>\n<ul>\n<li>Change points shape and color by groups<\/li>\n<li>Adjust the degree of jittering: <code>position_jitter(0.2)<\/code><\/li>\n<li>Add summary statistics:<\/li>\n<\/ul>\n<pre class=\"r\"><code># Initiate a ggplot\r\ne &lt;- ggplot(ToothGrowth, aes(x = dose, y = len))\r\n\r\n# Stripcharts with summary statistics\r\n# Change color by dose groups\r\ne + geom_jitter(aes(shape = dose, color = dose), \r\n                position = position_jitter(0.2), size = 1.2) +\r\n  stat_summary(aes(color = dose), size = 0.4,\r\n               fun.data=\"mean_sdl\",  fun.args = list(mult=1))+\r\n  scale_color_manual(values =  c(\"#00AFBB\", \"#E7B800\", \"#FC4E07\"))<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/ggplot2\/figures\/008-ggplot-stripchart-geom_jitter-basic-stripcharts-1.png\" width=\"384\" \/><\/p>\n<div class=\"notice\">\n<p>The function <code>mean_sdl<\/code> is used for adding mean and standard deviation. It computes the mean plus or minus a constant times the standard deviation. In the R code above, the constant is specified using the argument <code>mult<\/code> (mult = 1). By default mult = 2. The mean +\/- SD can be added as a crossbar or a pointrange.<\/p>\n<\/div>\n<\/div>\n<div id=\"combine-with-box-plots-and-violin-plots\" class=\"section level2\">\n<h2>Combine with box plots and violin plots<\/h2>\n<pre class=\"r\"><code># Combine with box plot\r\ne + geom_boxplot() + \r\n  geom_jitter(position = position_jitter(0.2))\r\n\r\n  \r\n# Strip chart + violin plot + stat summary\r\ne + geom_violin(trim = FALSE) +\r\n  geom_jitter(position = position_jitter(0.2)) +\r\n  stat_summary(fun.data=\"mean_sdl\",  fun.args = list(mult=1),\r\n               color = \"red\")<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/ggplot2\/figures\/008-ggplot-stripchart-stripchart-combine-1.png\" width=\"240\" \/><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/ggplot2\/figures\/008-ggplot-stripchart-stripchart-combine-2.png\" width=\"240\" \/><\/p>\n<\/div>\n<div id=\"create-a-stripchart-with-multiple-groups\" class=\"section level2\">\n<h2>Create a stripchart with multiple groups<\/h2>\n<p>The R code is similar to what we have seen in dot plots section. However, to create dodged jitter points, you should use the function <code>position_jitterdodge()<\/code> instead of <code>position_dodge()<\/code>.<\/p>\n<pre class=\"r\"><code>e + geom_jitter(\r\n  aes(shape = supp, color = supp), size = 1.2,\r\n  position = position_jitterdodge(jitter.width = 0.2, dodge.width = 0.8)\r\n  ) +\r\n  stat_summary(\r\n    aes(color = supp), fun.data=\"mean_sdl\", fun.args = list(mult=1), \r\n    size = 0.4, position = position_dodge(0.8)\r\n    )+\r\n  scale_color_manual(values =  c(\"#00AFBB\", \"#E7B800\"))<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/dn-tutorials\/ggplot2\/figures\/008-ggplot-stripchart-geom_jitter-stripcharts-for-multiple-groups-1.png\" width=\"307.2\" \/><\/p>\n<\/div>\n<div id=\"conclusion\" class=\"section level2\">\n<h2>Conclusion<\/h2>\n<p>This article describes how to create a stripchart using the ggplot2 package.<\/p>\n<\/div>\n<\/div>\n<p><!--end rdoc--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Stripcharts are also known as one dimensional scatter plots. These plots are suitable compared to box plots when sample sizes are small. This article describes how to create and customize Stripcharts using the ggplot2 R package.<\/p>\n","protected":false},"author":1,"featured_media":7906,"parent":0,"menu_order":10,"comment_status":"open","ping_status":"closed","template":"","class_list":["post-8319","dt_lessons","type-dt_lessons","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>GGPlot Stripchart Best Reference - Datanovia<\/title>\n<meta name=\"description\" content=\"This article describes how to create and customize Stripcharts using the ggplot2 R package. Stripcharts are also known as one dimensional scatter plots.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"GGPlot Stripchart Best Reference - Datanovia\" \/>\n<meta property=\"og:description\" content=\"This article describes how to create and customize Stripcharts using the ggplot2 R package. Stripcharts are also known as one dimensional scatter plots.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/\" \/>\n<meta property=\"og:site_name\" content=\"Datanovia\" \/>\n<meta property=\"article:modified_time\" content=\"2019-11-17T21:06:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_2138.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/\",\"url\":\"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/\",\"name\":\"GGPlot Stripchart Best Reference - Datanovia\",\"isPartOf\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_2138.jpg\",\"datePublished\":\"2018-12-30T23:29:02+00:00\",\"dateModified\":\"2019-11-17T21:06:13+00:00\",\"description\":\"This article describes how to create and customize Stripcharts using the ggplot2 R package. Stripcharts are also known as one dimensional scatter plots.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/#primaryimage\",\"url\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_2138.jpg\",\"contentUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_2138.jpg\",\"width\":1024,\"height\":512},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.datanovia.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Lessons\",\"item\":\"https:\/\/www.datanovia.com\/en\/lessons\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"GGPlot Stripchart\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#website\",\"url\":\"https:\/\/www.datanovia.com\/en\/\",\"name\":\"Datanovia\",\"description\":\"Data Mining and Statistics for Decision Support\",\"publisher\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.datanovia.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#organization\",\"name\":\"Datanovia\",\"url\":\"https:\/\/www.datanovia.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png\",\"contentUrl\":\"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png\",\"width\":98,\"height\":99,\"caption\":\"Datanovia\"},\"image\":{\"@id\":\"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"GGPlot Stripchart Best Reference - Datanovia","description":"This article describes how to create and customize Stripcharts using the ggplot2 R package. Stripcharts are also known as one dimensional scatter plots.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/","og_locale":"en_US","og_type":"article","og_title":"GGPlot Stripchart Best Reference - Datanovia","og_description":"This article describes how to create and customize Stripcharts using the ggplot2 R package. Stripcharts are also known as one dimensional scatter plots.","og_url":"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/","og_site_name":"Datanovia","article_modified_time":"2019-11-17T21:06:13+00:00","og_image":[{"width":1024,"height":512,"url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_2138.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/","url":"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/","name":"GGPlot Stripchart Best Reference - Datanovia","isPartOf":{"@id":"https:\/\/www.datanovia.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/#primaryimage"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/#primaryimage"},"thumbnailUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_2138.jpg","datePublished":"2018-12-30T23:29:02+00:00","dateModified":"2019-11-17T21:06:13+00:00","description":"This article describes how to create and customize Stripcharts using the ggplot2 R package. Stripcharts are also known as one dimensional scatter plots.","breadcrumb":{"@id":"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/#primaryimage","url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_2138.jpg","contentUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/10\/IMG_2138.jpg","width":1024,"height":512},{"@type":"BreadcrumbList","@id":"https:\/\/www.datanovia.com\/en\/lessons\/ggplot-stripchart\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.datanovia.com\/en\/"},{"@type":"ListItem","position":2,"name":"Lessons","item":"https:\/\/www.datanovia.com\/en\/lessons\/"},{"@type":"ListItem","position":3,"name":"GGPlot Stripchart"}]},{"@type":"WebSite","@id":"https:\/\/www.datanovia.com\/en\/#website","url":"https:\/\/www.datanovia.com\/en\/","name":"Datanovia","description":"Data Mining and Statistics for Decision Support","publisher":{"@id":"https:\/\/www.datanovia.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.datanovia.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.datanovia.com\/en\/#organization","name":"Datanovia","url":"https:\/\/www.datanovia.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png","contentUrl":"https:\/\/www.datanovia.com\/en\/wp-content\/uploads\/2018\/09\/datanovia-logo.png","width":98,"height":99,"caption":"Datanovia"},"image":{"@id":"https:\/\/www.datanovia.com\/en\/#\/schema\/logo\/image\/"}}]}},"multi-rating":{"mr_rating_results":[]},"_links":{"self":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons\/8319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons"}],"about":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/types\/dt_lessons"}],"author":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/comments?post=8319"}],"version-history":[{"count":1,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons\/8319\/revisions"}],"predecessor-version":[{"id":10454,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/dt_lessons\/8319\/revisions\/10454"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media\/7906"}],"wp:attachment":[{"href":"https:\/\/www.datanovia.com\/en\/wp-json\/wp\/v2\/media?parent=8319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}