<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/using-cranlogs-in-r-with-plotly/"></div></div><div><a data-url="https://www.r-bloggers.com/using-cranlogs-in-r-with-plotly/" data-counturl="https://www.r-bloggers.com/using-cranlogs-in-r-with-plotly/" data-count="horizontal" data-text="Using cranlogs in R with 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/using-cranlogs-in-r-with-plotly/"> R – Modern Data</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>In this post we’ll use the <b>cranlogs</b> package to visualize the number of downloads for <a target="_blank" href="https://plot.ly/r/">Plotly’s R API</a></p>

<pre>library(cranlogs)
library(plotly)
library(zoo)

# Get data
df &lt;- cran_downloads(packages = c(&quot;plotly&quot;, &quot;ggplot2&quot;), 
                     from = &quot;2015-10-01&quot;, to = &quot;2016-08-01&quot;)

# Convert dates
df$date &lt;- as.Date(df$date)

# Make data frame
df &lt;- data.frame(date = unique(df$date),
                 count.plotly = subset(df, package == &quot;plotly&quot;)$count,
                 count.ggplot = subset(df, package == &quot;ggplot2&quot;)$count)

# Smooth data 
# 5 day moving averages
nWidth &lt;- 5
df &lt;- zoo(df[,-1], order.by = df[,1])
df.smooth &lt;- rollapply(df, width = nWidth, FUN = mean)

df &lt;- data.frame(date = index(df.smooth),
                 count.plotly = round(df.smooth[,1],0),
                 count.ggplot = round(df.smooth[,2],0))

plot_ly(df, x = ~date) %>% 
  add_lines(y = ~count.plotly, fill = &quot;tozeroy&quot;, line = list(shape = &quot;spline&quot;), name = &quot;Plotly&quot;) %>% 
  add_lines(y = ~count.ggplot, fill = &quot;tozeroy&quot;, line = list(shape = &quot;spline&quot;), name = &quot;ggplot2&quot;, 
            yaxis = &quot;y2&quot;, xaxis = &quot;x2&quot;) %>% 
  
  layout(yaxis = list(domain = c(0.55,1), title = &quot;Count&quot;, anchor = &quot;xaxis&quot;,
                      tickfont = list(color = &quot;#595959&quot;, size = 12)),
         
         yaxis2 = list(domain = c(0, 0.45), title = &quot;Count&quot;, anchor = &quot;xaxis2&quot;,
                       tickfont = list(color = &quot;#595959&quot;, size = 12)),
         
         xaxis = list(anchor = &quot;yaxis&quot;, title = &quot;Date&quot;),
         
         xaxis2 = list(anchor = &quot;free&quot;, title = &quot;Date&quot;),
         
         annotations = list(
           
           list(x = 0.05, y = 1, xref = &quot;paper&quot;, yref = &quot;paper&quot;,
                showarrow = FALSE,
                text = &quot;&lt;b>Plotly downloads&lt;/b>&quot;,
                font = list(size = 17)),
           
           list(x = 0.05, y = 0.45, xref = &quot;paper&quot;, yref = &quot;paper&quot;,
                showarrow = FALSE,
                text = &quot;&lt;b>ggplot2 downloads&lt;/b>&quot;,
                font = list(size = 17))))</pre>
<p><code>
<p><iframe height="800" width="450" src="https://plot.ly/~riddhiman/379.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="https://www.r-bloggers.com/using-cranlogs-in-r-with-plotly/"></div></div><div><a data-url="https://www.r-bloggers.com/using-cranlogs-in-r-with-plotly/" data-counturl="https://www.r-bloggers.com/using-cranlogs-in-r-with-plotly/" data-count="vertical" data-text="Using cranlogs in R with 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/using-cranlogs-in-r-with-plotly/"> R – Modern Data</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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/U8SjsBVF-oU"></a></div></code>