<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/beeswarms-instead-of-histograms/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://aghaynes.wordpress.com/2018/06/28/beeswarms-instead-of-histograms/"> R – Insights of a PhD</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Histograms are good, density plots are also good. Violin and bean plots too. Recently I had someone ask for a plot where you could see each individual point along a continuum, give the points specific colours based on a second variable (similar to the figure), which deviates somewhat from the typical density type plots. Apparently, they’re called beeplots or beeswarms. And there’s a way to make them in R (of course, there’s probably more than one… ggplot2??).</p>
<p><img data-orig-file="https://aghaynes.files.wordpress.com/2018/06/beeswarm.png?w=450&amp;h=385&amp;fit=482%2C385" data-orig-size="608,486" data-medium-file="https://aghaynes.files.wordpress.com/2018/06/beeswarm.png?w=450&amp;h=385&amp;fit=482%2C385?w=300" data-attachment-id="373" data-image-meta="{" data-image-description="" src="https://aghaynes.files.wordpress.com/2018/06/beeswarm.png?w=450&h=385&fit=482%2C385" data-permalink="https://aghaynes.wordpress.com/2018/06/28/beeswarms-instead-of-histograms/beeswarm/" data-large-file="https://aghaynes.files.wordpress.com/2018/06/beeswarm.png?w=450&amp;h=385&amp;fit=482%2C385?w=497" alt="beeswarm" data-image-title="beeswarm" sizes="(max-width: 482px) 100vw, 482px" data-comments-opened="1" class="wp-image-373" data-recalc-dims="1"></p>
<p>Here’s one way (slightly modified from the packages help files)…</p>
<pre>library(beeswarm) # assuming you've installed it ;)
data(breast)
beeswarm(time_survival ~ ER, data = breast,
         pch = 16, pwcol = 1 + as.numeric(event_survival),
         xlab = &quot;&quot;, ylab = &quot;Follow-up time (months)&quot;, horizontal = TRUE, 
         labels = c(&quot;ER neg&quot;, &quot;ER pos&quot;), method = &quot;c&quot;)
legend(&quot;topright&quot;, legend = c(&quot;Yes&quot;, &quot;No&quot;),
       title = &quot;Censored&quot;, pch = 16, col = 1:2)

</pre>
<p>Horizontal is optional of course…</p>
<p>Feel free to comment if you know of other approaches.</p>
<p>See <a rel="nofollow" href="http://www.cbs.dtu.dk/~eklund/beeswarm/" target="_blank">here for more examples</a>.</p>
<p>Hope that helps someone <img alt="🙂" src="https://i0.wp.com/s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f642.png?w=456&ssl=1" class="wp-smiley" data-recalc-dims="1"></p>
<p> </p>
<p> </p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://aghaynes.wordpress.com/2018/06/28/beeswarms-instead-of-histograms/"> R – Insights of a PhD</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/uk82qoQf8aU" height="1"></a></div>