<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/bullet-charts-in-r-using-plotly/"></div></div><div><a data-url="http://www.r-bloggers.com/bullet-charts-in-r-using-plotly/" data-counturl="http://www.r-bloggers.com/bullet-charts-in-r-using-plotly/" data-count="horizontal" data-text="Bullet Charts in R using Plotly" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://moderndata.plot.ly/bullet-charts-in-r-using-plotly/"> R – Modern Data</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>This post is inspired by Mike Bostock’s implementation of bullet charts – <a href="http://bl.ocks.org/mbostock/4061961">http://bl.ocks.org/mbostock/4061961</a></p>

<pre>library(plotly)
library(jsonlite)
library(dplyr)

# Read data
df &lt;- fromJSON(txt = url(&quot;https://cdn.rawgit.com/plotly/datasets/master/BulletData.json&quot;))

# Convert to conventional format
df &lt;- t(apply(df, 1, function(vec){
  vec &lt;- unlist(vec)
  return(vec)
}))

df &lt;- as.data.frame(df, stringsAsFactors = F)
p &lt;- list()

# Set line widths
innerwidth &lt;- 10
outerwidth &lt;- 25

for(i in 1:nrow(df)){
  p[[i]] &lt;- 
    
    # Ranges3
    plot_ly(df[i,], 
            x = c(0, as.numeric(ranges3)),
            y = c(title, title),
            name = &quot;Range3&quot;,
            hoverinfo = &quot;x&quot;,
            mode = &quot;lines&quot;,
            line = list(color = &quot;#eeeeee&quot;, width = outerwidth),
            evaluate = T) %>% 
    
    # Ranges2
    add_trace(x = c(0, as.numeric(ranges2)),
              y = c(title, title),
              hoverinfo = &quot;x&quot;,
              mode = &quot;lines&quot;,
              line = list(color = &quot;#dddddd&quot;, width = outerwidth),
              evaluate = T) %>%
    
    # Ranges1
    add_trace(x = c(0, as.numeric(ranges1)),
              y = c(title, title),
              hoverinfo = &quot;x&quot;,
              line = list(color = &quot;#cccccc&quot;, width = outerwidth),
              evaluate = T) %>% 
    
    
    # Measure2
    add_trace(x = c(0, as.numeric(measures2)),
              y = c(title, title),
              mode = &quot;lines&quot;,
              hoverinfo = &quot;x&quot;,
              line = list(color = &quot;#b0c4de&quot;, width = innerwidth),
              evaluate = T) %>% 
    
    # Measure1
    add_trace(x = c(0, as.numeric(measures1)),
              y = c(title, title),
              mode = &quot;lines&quot;,
              hoverinfo = &quot;x&quot;,
              line = list(color = &quot;#4682b4&quot;, width = innerwidth),
              evaluate = T) %>% 
    
    # Marker
    add_trace(x = as.numeric(markers),
              y = title,
              mode = &quot;markers&quot;,
              hoverinfo = &quot;x&quot;,
              marker = list(color = &quot;black&quot;, symbol = &quot;diamond-tall&quot;, size = 10),
              evaluate = T) %>% 
    
    layout(showlegend = F, 
           xaxis = list(title = &quot;&quot;, showgrid = F, zeroline = F, 
                        range = c(-(as.numeric(ranges3)/10), as.numeric(ranges3)),
                        ticklen = 7,
                        tickfont = list(family = &quot;Arial&quot;, size = 10),
                        tickcolor = &quot;#cccccc&quot;),
           
           yaxis = list(title = &quot;&quot;,
                        showgrid = F, 
                        zeroline = F,
                        showticklabels = F))
}

pp &lt;- subplot(p[[1]], p[[2]], p[[3]], p[[4]], p[[5]],
        nrows = 5, 
        margin = c(0, 0, 0.1, 0))

# Add Y-Axis titles
pp &lt;- layout(pp,
       annotations = list(
         
         list(xref = &quot;paper&quot;, yref = &quot;paper&quot;, 
              x = 0, y = 0.05, ax = 0, ay = 0, xanchor = &quot;right&quot;,
              text = paste0(&quot;&lt;b>&quot;, df[1,1], &quot;&lt;/b>&quot;,&quot;&lt;br>&quot;,
                            '&lt;span style = &quot;color:grey; font-size:75%&quot;>', 
                            df[1,2], &quot;&lt;/span>&quot;),
              align = &quot;right&quot;,
              font = list(family = &quot;arial&quot;,
                          size = 15)),
         
         list(xref = &quot;paper&quot;, yref = &quot;paper&quot;, 
              x = 0, y = 0.25, ax = 0, ay = 0, xanchor = &quot;right&quot;,
              text = paste0(&quot;&lt;b>&quot;, df[2,1], &quot;&lt;/b>&quot;,&quot;&lt;br>&quot;,
                            '&lt;span style = &quot;color:grey; font-size:75%&quot;>', 
                            df[2,2], &quot;&lt;/span>&quot;),
              align = &quot;right&quot;,
              font = list(family = &quot;arial&quot;,
                          size = 15)),
         
         list(xref = &quot;paper&quot;, yref = &quot;paper&quot;, 
              x = 0, y = 0.45, ax = 0, ay = 0, xanchor = &quot;right&quot;,
              text = paste0(&quot;&lt;b>&quot;, df[3,1], &quot;&lt;/b>&quot;,&quot;&lt;br>&quot;,
                            '&lt;span style = &quot;color:grey; font-size:75%&quot;>', 
                            df[3,2], &quot;&lt;/span>&quot;),
              align = &quot;right&quot;,
              font = list(family = &quot;arial&quot;,
                          size = 15)),
         
         list(xref = &quot;paper&quot;, yref = &quot;paper&quot;, 
              x = 0, y = 0.65, ax = 0, ay = 0, xanchor = &quot;right&quot;,
              text = paste0(&quot;&lt;b>&quot;, df[4,1], &quot;&lt;/b>&quot;,&quot;&lt;br>&quot;,
                            '&lt;span style = &quot;color:grey; font-size:75%&quot;>', 
                            df[4,2], &quot;&lt;/span>&quot;),
              align = &quot;right&quot;,
              font = list(family = &quot;arial&quot;,
                          size = 15)),
         
         list(xref = &quot;paper&quot;, yref = &quot;paper&quot;, 
              x = 0, y = 0.90, ax = 0, ay = 0, xanchor = &quot;right&quot;,
              text = paste0(&quot;&lt;b>&quot;, df[5,1], &quot;&lt;/b>&quot;,&quot;&lt;br>&quot;,
                            '&lt;span style = &quot;color:grey; font-size:75%&quot;>', 
                            df[5,2], &quot;&lt;/span>&quot;),
              align = &quot;right&quot;,
              font = list(family = &quot;arial&quot;,
                          size = 15))))

pp</pre>

<p><iframe height="500" width="1200" src="https://plot.ly/~riddhiman/279.embed"></iframe></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/bullet-charts-in-r-using-plotly/"></div></div><div><a data-url="http://www.r-bloggers.com/bullet-charts-in-r-using-plotly/" data-counturl="http://www.r-bloggers.com/bullet-charts-in-r-using-plotly/" data-count="vertical" data-text="Bullet Charts in R using Plotly" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://moderndata.plot.ly/bullet-charts-in-r-using-plotly/"> R – Modern Data</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/s1K5caH9oeI"></a></div>