<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/corrr-0-2-1-now-on-cran/"></div></div><div><a data-url="https://www.r-bloggers.com/corrr-0-2-1-now-on-cran/" data-counturl="https://www.r-bloggers.com/corrr-0-2-1-now-on-cran/" data-count="horizontal" data-text="corrr 0.2.1 now on CRAN" 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://drsimonj.svbtle.com/corrr-021-now-on-cran"> blogR</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a target="_blank" href="https://twitter.com/drsimonj">@drsimonj</a> here to discuss the latest CRAN release of <strong>corrr</strong> (0.2.1), a package for exploring <strong>corr</strong>elations in a tidy <strong>R</strong> framework. This post will describe corrr features added since version 0.1.0.</p>
<p>You can install or update to this latest version directly from CRAN by running:</p>
<pre><code>install.packages(corrr)
</code></pre>
<p>Let’s load corrr into our workspace and create a correlation data frame of the mtcars data set to work with:</p>
<pre><code>library(corrr)
rdf &lt;- correlate(mtcars)
rdf
#> # A tibble: 11 × 12
#>    rowname        mpg        cyl       disp         hp        drat
#>      &lt;chr>      &lt;dbl>      &lt;dbl>      &lt;dbl>      &lt;dbl>       &lt;dbl>
#> 1      mpg         NA -0.8521620 -0.8475514 -0.7761684  0.68117191
#> 2      cyl -0.8521620         NA  0.9020329  0.8324475 -0.69993811
#> 3     disp -0.8475514  0.9020329         NA  0.7909486 -0.71021393
#> 4       hp -0.7761684  0.8324475  0.7909486         NA -0.44875912
#> 5     drat  0.6811719 -0.6999381 -0.7102139 -0.4487591          NA
#> 6       wt -0.8676594  0.7824958  0.8879799  0.6587479 -0.71244065
#> 7     qsec  0.4186840 -0.5912421 -0.4336979 -0.7082234  0.09120476
#> 8       vs  0.6640389 -0.8108118 -0.7104159 -0.7230967  0.44027846
#> 9       am  0.5998324 -0.5226070 -0.5912270 -0.2432043  0.71271113
#> 10    gear  0.4802848 -0.4926866 -0.5555692 -0.1257043  0.69961013
#> 11    carb -0.5509251  0.5269883  0.3949769  0.7498125 -0.09078980
#> # ... with 6 more variables: wt &lt;dbl>, qsec &lt;dbl>, vs &lt;dbl>, am &lt;dbl>,
#> #   gear &lt;dbl>, carb &lt;dbl>
</code></pre>
<h2><a target="_blank" href="http://drsimonj.svbtle.com/corrr-021-now-on-cran#plotting-functions_2"> </a>Plotting functions</h2>
<p>The significant changes involve the <code>rplot()</code> and new <code>network_plot()</code> functions that support the visualisation of your correlations.</p>
<h3><a target="_blank" href="http://drsimonj.svbtle.com/corrr-021-now-on-cran#rplot_3"> </a>rplot()</h3>
<p><code>rplot()</code> produces a shape plot of the correlations. More visible dots correspond to stronger correlations, and blue and red respectively to positive and negative. The default plot looks like this:</p>
<pre><code>rplot(rdf)
</code></pre>
<p><a target="_blank" href="https://i1.wp.com/svbtleusercontent.com/tybc2xtatsexyw.png?ssl=1"><img alt="rplot1-1.png" src="https://i2.wp.com/svbtleusercontent.com/tybc2xtatsexyw_small.png?w=456&ssl=1" data-recalc-dims="1"></a></p>
<p>There are now four arguments that allow you to make adjustments to this plot:</p>
<ul>
<li> <code>legend</code> Boolean indicating whether a legend mapping the colours to the correlations should be displayed.</li>
<li> <code>shape</code> geom_point aesthetic. A number corresponding to the shape of each point. See <a target="_blank" href="http://sape.inf.usi.ch/quick-reference/ggplot2/shape">http://sape.inf.usi.ch/quick-reference/ggplot2/shape</a></li>
<li> <code>colours</code> or <code>colors</code> Vector of colours to use for n-colour gradient. See <a target="_blank" href="http://sape.inf.usi.ch/quick-reference/ggplot2/colour">http://sape.inf.usi.ch/quick-reference/ggplot2/colour</a></li>
<li> <code>print_cor</code> Boolean indicating whether the correlations should be printed over the shapes.</li>
</ul>
<p>Here are some examples that change these values:</p>
<pre><code>rplot(rdf, legend = TRUE, shape = 1)
</code></pre>
<p><a target="_blank" href="https://i2.wp.com/svbtleusercontent.com/4vu80lla0m57tw.png?ssl=1"><img alt="rplot-shape-1.png" src="https://i1.wp.com/svbtleusercontent.com/4vu80lla0m57tw_small.png?w=456&ssl=1" data-recalc-dims="1"></a></p>
<pre><code>rplot(rdf, legend = TRUE, colours = c(&quot;firebrick1&quot;, &quot;black&quot;, &quot;darkcyan&quot;))
</code></pre>
<p><a target="_blank" href="https://i1.wp.com/svbtleusercontent.com/829g4miotbdlq.png?ssl=1"><img alt="rplot-color-1.png" src="https://i2.wp.com/svbtleusercontent.com/829g4miotbdlq_small.png?w=456&ssl=1" data-recalc-dims="1"></a></p>
<pre><code>rplot(rdf, print_cor = TRUE)
</code></pre>
<p><a target="_blank" href="https://i0.wp.com/svbtleusercontent.com/qt7l9kapdh66ug.png?ssl=1"><img alt="rplot-print-1.png" src="https://i1.wp.com/svbtleusercontent.com/qt7l9kapdh66ug_small.png?w=456&ssl=1" data-recalc-dims="1"></a></p>
<p>And don’t forget that you can <code>rearrange()</code> your correlations first:</p>
<pre><code>rdf %>% rearrange(absolute = FALSE) %>% rplot(shape = 0, print_cor = TRUE)
</code></pre>
<p><a target="_blank" href="https://i0.wp.com/svbtleusercontent.com/auyi27hd5aq.png?ssl=1"><img alt="rplot-rear-1.png" src="https://i0.wp.com/svbtleusercontent.com/auyi27hd5aq_small.png?w=456&ssl=1" data-recalc-dims="1"></a></p>
<h3><a target="_blank" href="http://drsimonj.svbtle.com/corrr-021-now-on-cran#networkplot_3"> </a>network_plot()</h3>
<p><code>network_plot()</code> produces a network that lays out and connects variables based on the strength of their correlations:</p>
<pre><code>network_plot(rdf)
</code></pre>
<p><a target="_blank" href="https://i0.wp.com/svbtleusercontent.com/0mkxgsp06b0iuq.png?ssl=1"><img alt="netplot1-1.png" src="https://i2.wp.com/svbtleusercontent.com/0mkxgsp06b0iuq_small.png?w=456&ssl=1" data-recalc-dims="1"></a></p>
<p>For a good intro to <code>network_plot()</code>, see my <a target="_blank" href="https://drsimonj.svbtle.com/correlation-network-plot-with-corrr">previous blogR post</a>. Three arguments allow you to adjust this plot:</p>
<ul>
<li> <code>min_cor</code> Number from 0 to 1 indicating the minimum value of correlations (in absolute terms) to plot.</li>
<li> <code>legend</code> same as <code>rplot()</code></li>
<li> <code>colours</code> or <code>colors</code> same as <code>rplot()</code></li>
</ul>
<p>Some examples:</p>
<pre><code>network_plot(rdf, legend = TRUE, colours = c(&quot;slategrey&quot;, &quot;palegreen&quot;))
</code></pre>
<p><a target="_blank" href="https://i2.wp.com/svbtleusercontent.com/skyi6gomrf1pg.png?ssl=1"><img alt="netplot-egs-1.png" src="https://i1.wp.com/svbtleusercontent.com/skyi6gomrf1pg_small.png?w=456&ssl=1" data-recalc-dims="1"></a></p>
<pre><code>
network_plot(rdf, legend = TRUE, min_cor = .7)
</code></pre>
<p><a target="_blank" href="https://i0.wp.com/svbtleusercontent.com/ajvkp1eb8u9img.png?ssl=1"><img alt="netplot-egs-2.png" src="https://i1.wp.com/svbtleusercontent.com/ajvkp1eb8u9img_small.png?w=456&ssl=1" data-recalc-dims="1"></a></p>
<h2><a target="_blank" href="http://drsimonj.svbtle.com/corrr-021-now-on-cran#other-features_2"> </a>Other features</h2>
<h3><a target="_blank" href="http://drsimonj.svbtle.com/corrr-021-now-on-cran#fashion_3"> </a>fashion()</h3>
<p><code>fashion()</code> will now try to work on almost any object (not just correlation data frames). It also provides arguments to adjust the number of <code>decimals</code>, whether to display <code>leading_zeros</code>, and how to print missing values (<code>na_print</code>):</p>
<pre><code>fashion(rdf)
#>    rowname  mpg  cyl disp   hp drat   wt qsec   vs   am gear carb
#> 1      mpg      -.85 -.85 -.78  .68 -.87  .42  .66  .60  .48 -.55
#> 2      cyl -.85       .90  .83 -.70  .78 -.59 -.81 -.52 -.49  .53
#> 3     disp -.85  .90       .79 -.71  .89 -.43 -.71 -.59 -.56  .39
#> 4       hp -.78  .83  .79      -.45  .66 -.71 -.72 -.24 -.13  .75
#> 5     drat  .68 -.70 -.71 -.45      -.71  .09  .44  .71  .70 -.09
#> 6       wt -.87  .78  .89  .66 -.71      -.17 -.55 -.69 -.58  .43
#> 7     qsec  .42 -.59 -.43 -.71  .09 -.17       .74 -.23 -.21 -.66
#> 8       vs  .66 -.81 -.71 -.72  .44 -.55  .74       .17  .21 -.57
#> 9       am  .60 -.52 -.59 -.24  .71 -.69 -.23  .17       .79  .06
#> 10    gear  .48 -.49 -.56 -.13  .70 -.58 -.21  .21  .79       .27
#> 11    carb -.55  .53  .39  .75 -.09  .43 -.66 -.57  .06  .27

fashion(mtcars) %>% head()
#>     mpg  cyl   disp     hp drat   wt  qsec   vs   am gear carb
#> 1 21.00 6.00 160.00 110.00 3.90 2.62 16.46  .00 1.00 4.00 4.00
#> 2 21.00 6.00 160.00 110.00 3.90 2.88 17.02  .00 1.00 4.00 4.00
#> 3 22.80 4.00 108.00  93.00 3.85 2.32 18.61 1.00 1.00 4.00 1.00
#> 4 21.40 6.00 258.00 110.00 3.08 3.21 19.44 1.00  .00 3.00 1.00
#> 5 18.70 8.00 360.00 175.00 3.15 3.44 17.02  .00  .00 3.00 2.00
#> 6 18.10 6.00 225.00 105.00 2.76 3.46 20.22 1.00  .00 3.00 1.00

fashion(c(0.340823, NA, -10.000032), decimals = 3, na_print = &quot;MISSING&quot;)
#> [1]    .341 MISSING -10.000

fashion(c(0.340823, NA, -10.000032), leading_zeros = TRUE)
#> [1]   0.34        -10.00
</code></pre>
<h3><a target="_blank" href="http://drsimonj.svbtle.com/corrr-021-now-on-cran#focus_3"> </a>focus()</h3>
<p>A standard evaluation version of <code>focus()</code> is now available, <code>focus_()</code>, to programatically focus on specific correlations:</p>
<pre><code>vars &lt;- c(&quot;mpg&quot;, &quot;disp&quot;)
focus_(rdf, &quot;hp&quot;, .dots = vars)
#> # A tibble: 8 × 4
#>   rowname         hp        mpg       disp
#>     &lt;chr>      &lt;dbl>      &lt;dbl>      &lt;dbl>
#> 1     cyl  0.8324475 -0.8521620  0.9020329
#> 2    drat -0.4487591  0.6811719 -0.7102139
#> 3      wt  0.6587479 -0.8676594  0.8879799
#> 4    qsec -0.7082234  0.4186840 -0.4336979
#> 5      vs -0.7230967  0.6640389 -0.7104159
#> 6      am -0.2432043  0.5998324 -0.5912270
#> 7    gear -0.1257043  0.4802848 -0.5555692
#> 8    carb  0.7498125 -0.5509251  0.3949769
</code></pre>
<h3><a target="_blank" href="http://drsimonj.svbtle.com/corrr-021-now-on-cran#bugs-and-stuff_3"> </a>Bugs and stuff</h3>
<p>Other than these, there have been fixes to various bugs and minor improvements made to existing functions. Please don’t forget to <a target="_blank" href="https://github.com/drsimonj/corrr/issues">open an issue on GitHub</a> or email me if you spot an issue or would like a new feature when using corrr.</p>
<h2><a target="_blank" href="http://drsimonj.svbtle.com/corrr-021-now-on-cran#acknowledgements_2"> </a>Acknowledgements</h2>
<p>Many thanks to the community who have already been using corrr and made suggestions along the way. Your help is invaluable for improving corrr!</p>
<h2><a target="_blank" href="http://drsimonj.svbtle.com/corrr-021-now-on-cran#sign-off_2"> </a>Sign off</h2>
<p>Thanks for reading and I hope this was useful for you.</p>
<p>For updates of recent blog posts, follow <a target="_blank" href="https://twitter.com/drsimonj">@drsimonj</a> on Twitter, or email me at <a target="_blank" href="mailto:drsimonjackson@gmail.com">drsimonjackson@gmail.com</a> to get in touch.</p>
<p>If you’d like the code that produced this blog, check out the <a target="_blank" href="https://github.com/drsimonj/blogR">blogR GitHub repository</a>.</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/corrr-0-2-1-now-on-cran/"></div></div><div><a data-url="https://www.r-bloggers.com/corrr-0-2-1-now-on-cran/" data-counturl="https://www.r-bloggers.com/corrr-0-2-1-now-on-cran/" data-count="vertical" data-text="corrr 0.2.1 now on CRAN" 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://drsimonj.svbtle.com/corrr-021-now-on-cran"> blogR</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/7wvmyji3wYI"></a></div>