<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/automated-dashboard-visualizations-with-deviation-in-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://datascienceplus.com/automated-dashboard-visualizations-with-deviation-in-r/"> R Programming – DataScience+</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<ul></ul>
<p><strong>
<p>Categories</p>
<p></p></strong>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/category/programming/" title="Permanent Link toProgramming" target="_blank">Programming</a></li>
</ol>
<p><strong>
<p>Tags</p>
<p></p></strong>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/data-visualisation/" title="Permanent Link toData Visualisation" target="_blank">Data Visualisation</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/r-markdown/" title="Permanent Link toR Markdown" target="_blank">R Markdown</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/rstats/" title="Permanent Link toR Programming" target="_blank">R Programming</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/tips-tricks/" title="Permanent Link toTips &amp; Tricks" target="_blank">Tips &amp; Tricks</a></li>
</ol>
<p>In this article, you learn how to make Automated Dashboard visualizations with Deviation in R. First you need to install the `rmarkdown` package into your R library. Assuming that you installed the `rmarkdown`, next you create a new `rmarkdown` script in R. </p>
<p>After this you type the following code in order to create a dashboard with <code>rmarkdown</code> and <code>flexdashboard</code>:</p>
<pre>
---
title: &quot;Dashboard visualizations in R: Deviation&quot;
author: &quot;Kristian Larsen&quot;
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: scroll
---

```{r setup, include=FALSE}
library(flexdashboard)
library(ggplot2)
library(plotly)
theme_set(theme_bw())  

# Data Prep
data(&quot;mtcars&quot;)  # load data
mtcars$`car name` &lt;- rownames(mtcars)  # create new column for car names
mtcars$mpg_z &lt;- round((mtcars$mpg - mean(mtcars$mpg))/sd(mtcars$mpg), 2)  # compute normalized mpg
mtcars$mpg_type &lt;- ifelse(mtcars$mpg_z &lt; 0, &quot;below&quot;, &quot;above&quot;)  # above / below avg flag
mtcars &lt;- mtcars[order(mtcars$mpg_z), ]  # sort
mtcars$`car name` &lt;- factor(mtcars$`car name`, levels = mtcars$`car name`)  # convert to factor to retain sorted order in plot.
```

Row
-----------------------------------------------------------------------

### Chart A: Diverging Barcharts

```{r}
ggplot(mtcars, aes(x=`car name`, y=mpg_z, label=mpg_z)) + 
  geom_bar(stat='identity', aes(fill=mpg_type), width=.5)  +
  scale_fill_manual(name=&quot;Mileage&quot;, 
                    labels = c(&quot;Above Average&quot;, &quot;Below Average&quot;), 
                    values = c(&quot;above&quot;=&quot;#00ba38&quot;, &quot;below&quot;=&quot;#f8766d&quot;)) + 
  labs(subtitle=&quot;Normalised mileage from 'mtcars'&quot;, 
       title= &quot;Diverging Bars&quot;) + 
  coord_flip()
ggplotly(p = ggplot2::last_plot())
```


### Chart B: Diverging Lollipop Chart

```{r}
library(ggplot2)
theme_set(theme_bw())

ggplot(mtcars, aes(x=`car name`, y=mpg_z, label=mpg_z)) + 
  geom_point(stat='identity', fill=&quot;black&quot;, size=6)  +
  geom_segment(aes(y = 0, 
                   x = `car name`, 
                   yend = mpg_z, 
                   xend = `car name`), 
               color = &quot;black&quot;) +
  geom_text(color=&quot;white&quot;, size=2) +
  labs(title=&quot;Diverging Lollipop Chart&quot;, 
       subtitle=&quot;Normalized mileage from 'mtcars': Lollipop&quot;) + 
  ylim(-2.5, 2.5) +
  coord_flip()
ggplotly(p = ggplot2::last_plot())
```

Row
-----------------------------------------------------------------------

### Cart C: Diverging Dot Plot



```{r}
library(ggplot2)
theme_set(theme_bw())

# Plot
ggplot(mtcars, aes(x=`car name`, y=mpg_z, label=mpg_z)) + 
  geom_point(stat='identity', aes(col=mpg_type), size=6)  +
  scale_color_manual(name=&quot;Mileage&quot;, 
                     labels = c(&quot;Above Average&quot;, &quot;Below Average&quot;), 
                     values = c(&quot;above&quot;=&quot;#00ba38&quot;, &quot;below&quot;=&quot;#f8766d&quot;)) + 
  geom_text(color=&quot;white&quot;, size=2) +
  labs(title=&quot;Diverging Dot Plot&quot;, 
       subtitle=&quot;Normalized mileage from 'mtcars': Dotplot&quot;) + 
  ylim(-2.5, 2.5) +
  coord_flip()
ggplotly(p = ggplot2::last_plot())
```


</pre>
<p>Screenshot:<br>
<a rel="nofollow" href="https://i0.wp.com/datascienceplus.com/wp-content/uploads/2018/12/V2-Deviation-Ranking-1.jpg?ssl=1" target="_blank"><img sizes="(max-width: 490px) 100vw, 490px" src="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2018/12/V2-Deviation-Ranking-1-490x167.jpg?w=450&ssl=1" alt="" class="wp-image-18885" data-recalc-dims="1"></a></p>
<p>The result of the above coding are published with RPubs <a rel="nofollow" href="http://rpubs.com/knl84/445411" target="_blank">here</a>.</p>
<h3>References</h3>
<ol>
<li><a rel="nofollow" href="https://rmarkdown.rstudio.com/flexdashboard/" target="_blank">Using flexdashboard in R</a></li>
</ol>
<p><strong>
<p>Related Post</p>
<p></p></strong>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/automated-dashboard-with-various-correlation-visualizations-in-r/" title="Permanent Link toAutomated Dashboard with various correlation visualizations in R" target="_blank">Automated Dashboard with various correlation visualizations in R</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/automated-dashboard-with-visualization-and-regression-for-healthcare-data/" title="Permanent Link toAutomated Dashboard with Visualization and Regression for Healthcare Data" target="_blank">Automated Dashboard with Visualization and Regression for Healthcare Data</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/create-easy-automated-dashbords-with-r-and-markdown/" title="Permanent Link toCreate easy automated dashbords with R and Markdown" target="_blank">Create easy automated dashbords with R and Markdown</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/send-desktop-notifications-from-r-in-windows-linux-and-mac/" title="Permanent Link toSend Desktop Notifications from R in Windows, Linux and Mac" target="_blank">Send Desktop Notifications from R in Windows, Linux and Mac</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/chaid-vs-ranger-vs-xgboost-a-comparison/" title="Permanent Link toCHAID vs. ranger vs. xgboost — a comparison" target="_blank">CHAID vs. ranger vs. xgboost — a comparison</a></li>
</ol>
	<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://datascienceplus.com/automated-dashboard-visualizations-with-deviation-in-r/"> R Programming – DataScience+</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 width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/epTcrBZAjyY" height="1"></a></div>