<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-ranking-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-ranking-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>
</ol>
<p>In this article, you learn how to make Automated Dashboard Visualizations with Ranking 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: Ranking&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)
# Prepare data: group mean city mileage by manufacturer.
cty_mpg &lt;- aggregate(mpg$cty, by=list(mpg$manufacturer), FUN=mean)  # aggregate
colnames(cty_mpg) &lt;- c(&quot;make&quot;, &quot;mileage&quot;)  # change column names
cty_mpg &lt;- cty_mpg[order(cty_mpg$mileage), ]  # sort
cty_mpg$make &lt;- factor(cty_mpg$make, levels = cty_mpg$make)  # to retain the order in plot.
```

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

### Chart A: Ordered Bar Chart

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

# Draw plot
ggplot(cty_mpg, aes(x=make, y=mileage)) + 
  geom_bar(stat=&quot;identity&quot;, width=.5, fill=&quot;tomato3&quot;) + 
  labs(title=&quot;Ordered Bar Chart&quot;, 
       subtitle=&quot;Make Vs Avg. Mileage&quot;, 
       caption=&quot;source: mpg&quot;) + 
  theme(axis.text.x = element_text(angle=65, vjust=0.6))
ggplotly(p = ggplot2::last_plot())
```


### Chart B: Lollipop Chart

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

# Plot
ggplot(cty_mpg, aes(x=make, y=mileage)) + 
  geom_point(size=3) + 
  geom_segment(aes(x=make, 
                   xend=make, 
                   y=0, 
                   yend=mileage)) + 
  labs(title=&quot;Lollipop Chart&quot;, 
       subtitle=&quot;Make Vs Avg. Mileage&quot;, 
       caption=&quot;source: mpg&quot;) + 
  theme(axis.text.x = element_text(angle=65, vjust=0.6))
ggplotly(p = ggplot2::last_plot())
```

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

### Cart C: Dot Plot



```{r}
library(ggplot2)
library(scales)
theme_set(theme_classic())

# Plot
ggplot(cty_mpg, aes(x=make, y=mileage)) + 
  geom_point(col=&quot;tomato2&quot;, size=3) +   # Draw points
  geom_segment(aes(x=make, 
                   xend=make, 
                   y=min(mileage), 
                   yend=max(mileage)), 
               linetype=&quot;dashed&quot;, 
               size=0.1) +   # Draw dashed lines
  labs(title=&quot;Dot Plot&quot;, 
       subtitle=&quot;Make Vs Avg. Mileage&quot;, 
       caption=&quot;source: mpg&quot;) +  
  coord_flip()
ggplotly(p = ggplot2::last_plot())
```

### Cart D: Slope Chart

```{r}
library(ggplot2)
library(scales)
theme_set(theme_classic())

# prep data
df &lt;- read.csv(&quot;https://raw.githubusercontent.com/selva86/datasets/master/gdppercap.csv&quot;)
colnames(df) &lt;- c(&quot;continent&quot;, &quot;1952&quot;, &quot;1957&quot;)
left_label &lt;- paste(df$continent, round(df$`1952`),sep=&quot;, &quot;)
right_label &lt;- paste(df$continent, round(df$`1957`),sep=&quot;, &quot;)
df$class &lt;- ifelse((df$`1957` - df$`1952`) &lt; 0, &quot;red&quot;, &quot;green&quot;)

# Plot
p &lt;- ggplot(df) + geom_segment(aes(x=1, xend=2, y=`1952`, yend=`1957`, col=class), size=.75, show.legend=F) + 
                  geom_vline(xintercept=1, linetype=&quot;dashed&quot;, size=.1) + 
                  geom_vline(xintercept=2, linetype=&quot;dashed&quot;, size=.1) +
                  scale_color_manual(labels = c(&quot;Up&quot;, &quot;Down&quot;), 
                                     values = c(&quot;green&quot;=&quot;#00ba38&quot;, &quot;red&quot;=&quot;#f8766d&quot;)) +  # color of lines
                  labs(x=&quot;&quot;, y=&quot;Mean GdpPerCap&quot;) +  # Axis labels
                  xlim(.5, 2.5) + ylim(0,(1.1*(max(df$`1952`, df$`1957`))))  # X and Y axis limits

# Add texts
p &lt;- p + geom_text(label=left_label, y=df$`1952`, x=rep(1, NROW(df)), hjust=1.1, size=3.5)
p &lt;- p + geom_text(label=right_label, y=df$`1957`, x=rep(2, NROW(df)), hjust=-0.1, size=3.5)
p &lt;- p + geom_text(label=&quot;Time 1&quot;, x=1, y=1.1*(max(df$`1952`, df$`1957`)), hjust=1.2, size=5)  # title
p &lt;- p + geom_text(label=&quot;Time 2&quot;, x=2, y=1.1*(max(df$`1952`, df$`1957`)), hjust=-0.1, size=5)  # title

# Minify theme
p + theme(panel.background = element_blank(), 
           panel.grid = element_blank(),
           axis.ticks = element_blank(),
           axis.text.x = element_blank(),
           panel.border = element_blank(),
           plot.margin = unit(c(1,2,1,2), &quot;cm&quot;))
ggplotly(p = ggplot2::last_plot())
```

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

### Cart E: Dumbbell Plot

```{r}
library(ggplot2)
library(ggalt)
theme_set(theme_classic())

health &lt;- read.csv(&quot;https://raw.githubusercontent.com/selva86/datasets/master/health.csv&quot;)
health$Area &lt;- factor(health$Area, levels=as.character(health$Area))  # for right ordering of the dumbells

# health$Area &lt;- factor(health$Area)
gg &lt;- ggplot(health, aes(x=pct_2013, xend=pct_2014, y=Area, group=Area)) + 
        geom_dumbbell(color=&quot;#a3c4dc&quot;, 
                      size=0.75, 
                      point.colour.l=&quot;#0e668b&quot;) + 
        scale_x_continuous(label=percent) + 
        labs(x=NULL, 
             y=NULL, 
             title=&quot;Dumbbell Chart&quot;, 
             subtitle=&quot;Pct Change: 2013 vs 2014&quot;, 
             caption=&quot;Source: https://github.com/hrbrmstr/ggalt&quot;) +
        theme(plot.title = element_text(hjust=0.5, face=&quot;bold&quot;),
              plot.background=element_rect(fill=&quot;#f7f7f7&quot;),
              panel.background=element_rect(fill=&quot;#f7f7f7&quot;),
              panel.grid.minor=element_blank(),
              panel.grid.major.y=element_blank(),
              panel.grid.major.x=element_line(),
              axis.ticks=element_blank(),
              legend.position=&quot;top&quot;,
              panel.border=element_blank())
plot(gg)
```
</pre>
<p>Screenshot:<br>
<a rel="nofollow" href="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2018/12/V3-Ranking.jpg?ssl=1" target="_blank"><img sizes="(max-width: 490px) 100vw, 490px" src="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2018/12/V3-Ranking-490x166.jpg?w=450&ssl=1" alt="" class="wp-image-18890" 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/445430" 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-visualizations-with-deviation-in-r/" title="Permanent Link toAutomated Dashboard visualizations with Deviation in R" target="_blank">Automated Dashboard visualizations with Deviation in R</a></li>
<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>
</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-ranking-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/xwNUbH-SlA8" height="1"></a></div>