<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/data-visualization-in-social-sciences-whats-new-in-the-sjplot-package-rstats/"></div></div><div><a data-url="http://www.r-bloggers.com/data-visualization-in-social-sciences-whats-new-in-the-sjplot-package-rstats/" data-counturl="http://www.r-bloggers.com/data-visualization-in-social-sciences-whats-new-in-the-sjplot-package-rstats/" data-count="horizontal" data-text="Data visualization in social sciences – what’s new in the sjPlot-package? #rstats" 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="https://strengejacke.wordpress.com/2016/05/19/data-visualization-in-social-sciences-whats-new-in-the-sjplot-package-rstats/"> R – Strenge Jacke!</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>My <a target="_blank" href="http://cran.r-project.org/package=sjPlot">sjPlot package</a> just reached version 2.0 and got many updates during the couple of last months. The focus was less on adding new functions; rather, I improved existing functions by adding new smaller and bigger features to make working with the package easier and more reliable. In this blog post, I will report some of the new features.</p>
<h1>Consistent name style of arguments</h1>
<p>Most notably, I tried to give all package functions a consistent naming style or pattern for arguments. In previous versions, mixing different name-styles was sometimes very confusing. For example, some functions used <code>showNA</code>, others <code>na.rm</code> or <code>show.na</code>. Or some functions used <code>hideLegend</code>, some <code>showLegend</code> and others again <code>show.legend</code>.</p>
<p>Now, all argument names are 1) lower case, 2) dot separated for longer words and are 3) grouped according to their function (i.e., if you open the docs for <code>?sjt.lm</code>, you’ll find all <code>show.</code> arguments, then all <code>string.</code> and finally all <code>digits.</code> arguments). I know that this means that you most likely have to completely re-write your code that uses sjPlot-function calls, but I think, in the long run, this makes working with the sjPlot package easier</p>
<h1>Support for different model families and link functions</h1>
<p>In previous package versions, functions related to generalized linear models (like <code>sjp.glm</code> or <code>sjp.glmer</code>) were hard coded for binomial model families for most plot types. Some effect or prediction plots only worked for logistic regression, because predictions were based on <code>plogis</code>. Also, automatic entitling of plots always included „probability“, even for count models.</p>
<p>In the past package updates and especially and the last major update, prediction or effect plot are now based on the link-inverse function of the models, so all common model families and link functions should work with sjPlot now.</p>
<h1>Predictions and effect plots</h1>
<p>In some cases, it is easier to interprete the predicted probabilities, incidents rates or marginal effects instead of the related estimate numbers (odds ratios, incident rate ratios, beta). For linear models (<code>sjp.lm</code>), linear mixed models (<code>sjp.lmer</code>), generalized linear models (<code>sjp.glm</code>) and generalized linear mixed models (<code>sjp.glmer</code>), there are three different plot types to plot predicted values or marginal effects:</p>
<ol>
<li><code>type = &quot;slope&quot;</code> (or <code>type = &quot;fe.slope&quot;</code> and <code>type = &quot;ri.slope&quot;</code> for mixed models) to plot unadjusted predicted values, i.e. the relation between model terms and response.</li>
<li><code>type = &quot;eff&quot;</code> to plot marginal effects, adjusted for all predictors.</li>
<li><code>type = &quot;pred&quot;</code> (and <code>type = &quot;pred.fe&quot;</code> for mixed models) to plot predicted values against reponse, for particular model terms.</li>
</ol>
<p>The following examples are taken from the <a target="_blank" href="http://www.strengejacke.de/sjPlot/sjp.glm/">vignette of the sjp.glm-function</a>.</p>
<h2>1. Predicted values, unadjusted</h2>
<p>The predicted values from this plot type are based on the intercept’s estimate and each specific term’s estimate. All other co-variates are set to zero (i.e. ignored), which corresponds to <code>family(fit)$linkinv(eta = b0 + bi * xi)</code> (where <em>xi</em> is the estimate).</p>
<p><a target="_blank" href="https://strengejacke.files.wordpress.com/2016/05/unnamed-chunk-7-1.png"><img height="214" alt="Predicted values, unadjusted" width="300" class="wp-image-1110" src="https://strengejacke.files.wordpress.com/2016/05/unnamed-chunk-7-1.png?w=300&h=214"></a></p>
<p>A probability curve of all predictors is plotted, which indicates the probability of the event (indicated by the response) occuring for each value of the predictor (not adjusted for remaining co-variates). In the above example, the first panel in the plot would be interpreted as: with increasing Barthel-Index (which means, better functional / physical status), the probability that caring for a dependent person is negatively perceived, decreases (in short: the less dependent a person I care for is, the less negative is the impact of care).</p>
<h2>2. Effect plots</h2>
<p>For marginal effects (predicted marginal probabilities resp. predicted marginal incident rates), all remaining co-variates are set to the mean, so this plot type adjusts for co-variates. Obtained results are based on the <a target="_blank" href="https://cran.r-project.org/package=effects">effects-package</a>.</p>
<p><a target="_blank" href="https://strengejacke.files.wordpress.com/2016/05/unnamed-chunk-11-1.png"><img height="214" alt="Marginal effects, adjusted" width="300" class="wp-image-1111" src="https://strengejacke.files.wordpress.com/2016/05/unnamed-chunk-11-1.png?w=300&h=214"></a></p>
<p>The effect plots can now also be non-faceted, and for selected model terms only (using the <code>facit.grid</code> and <code>vars</code> arguments).</p>
<h2>3. Predicting values</h2>
<p>The plot-type for predicting values did not produce any useful results in former package versions, because it just called the <code>predict</code> function without relationship to any predictor, or meaningful data. Now, this plot-type was completely revised. With <code>type = &quot;pred&quot;</code> (formerly, <code>&quot;y.pc&quot;</code>), you can plot predicted values for the response, related to specific model predictors. The predicted values of the response are computed, which corresponds to <code>predict(fit, type = &quot;response&quot;)</code>. This plot type requires the <code>vars</code> argument to select specific terms that should be used for the x-axis and – optional – as grouping factor. Hence, <code>vars</code> must be a character vector with the names of one or two model predictors.</p>
<p><a target="_blank" href="https://strengejacke.files.wordpress.com/2016/05/unnamed-chunk-12-1.png"><img height="214" alt="Predicting values" width="300" class="wp-image-1112" src="https://strengejacke.files.wordpress.com/2016/05/unnamed-chunk-12-1.png?w=300&h=214"></a></p>
<p><a target="_blank" href="https://strengejacke.files.wordpress.com/2016/05/unnamed-chunk-12-2.png"><img height="214" alt="Predicting values" width="300" class="wp-image-1113" src="https://strengejacke.files.wordpress.com/2016/05/unnamed-chunk-12-2.png?w=300&h=214"></a></p>
<h1>Table functions for mixed models</h1>
<p>The table functions were also revised, especially for mixed models. You now have more details in the random parts section of the table, which now also shows the variance components of the random parts, or (pseudo-)r<sup>2</sup>-values.</p>
<p>The tables are crated as HTML-page and displayed in your IDE’s viewer or your web browser. You can see many examples <a target="_blank" href="http://strengejacke.de/sjPlot/">at the package vignettes-page</a>. For the following example, I have taken a screenshot, because else the blog’s style sheet would break the table layout. Anyway, this is an example of a quickly produced table:</p>
<p><a target="_blank" href="https://strengejacke.files.wordpress.com/2016/05/table.png"><img height="179" alt="table" width="300" class="wp-image-1117" src="https://strengejacke.files.wordpress.com/2016/05/table.png?w=300&h=179"></a></p>
<h1>Closing remarks</h1>
<p>There have been a lot of improvements made in the sjPlot package during the past(s) updates. Above you see example of the most obvious user-visible changes. But there were also lots of other smaller and bigger improvements. E.g. plotting functions with different plot types, like <code>sjp.glm</code>, have many arguments; most of them only applied to specific plot types, while they were ignored by other plot types. Now, all plot types support more or mostly all arguments, and the documentation should be clearer about what the functions and their arguments do.</p>
<p>I hope you’ll enjoy the sjPlot-package. Feel free to submit issues or suggestions to <a target="_blank" href="https://github.com/sjPlot/devel/issues">the dedicated GitHub-page</a>.</p>
<p> Tagged: <a target="_blank" href="https://strengejacke.wordpress.com/tag/data-visualization/">data visualization</a>, <a target="_blank" href="https://strengejacke.wordpress.com/tag/ggplot/">ggplot</a>, <a target="_blank" href="https://strengejacke.wordpress.com/tag/r/">R</a>, <a target="_blank" href="https://strengejacke.wordpress.com/tag/rstats/">rstats</a>, <a target="_blank" href="https://strengejacke.wordpress.com/tag/sjplot/">sjPlot</a> <a target="_blank" rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/strengejacke.wordpress.com/1109/"><img alt="" src="http://feeds.wordpress.com/1.0/comments/strengejacke.wordpress.com/1109/" border="0"></a> <img height="1" alt="" width="1" src="https://pixel.wp.com/b.gif?host=strengejacke.wordpress.com&blog=10592659&%23038;post=1109&%23038;subd=strengejacke&%23038;ref=&%23038;feed=1" border="0"></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/data-visualization-in-social-sciences-whats-new-in-the-sjplot-package-rstats/"></div></div><div><a data-url="http://www.r-bloggers.com/data-visualization-in-social-sciences-whats-new-in-the-sjplot-package-rstats/" data-counturl="http://www.r-bloggers.com/data-visualization-in-social-sciences-whats-new-in-the-sjplot-package-rstats/" data-count="vertical" data-text="Data visualization in social sciences – what’s new in the sjPlot-package? #rstats" 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="https://strengejacke.wordpress.com/2016/05/19/data-visualization-in-social-sciences-whats-new-in-the-sjplot-package-rstats/"> R – Strenge Jacke!</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/LnD5YVP04hw"></a></div>