<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/ggedit-interactive-ggplot-aesthetic-and-theme-editor/"></div></div><div><a data-url="https://www.r-bloggers.com/ggedit-interactive-ggplot-aesthetic-and-theme-editor/" data-counturl="https://www.r-bloggers.com/ggedit-interactive-ggplot-aesthetic-and-theme-editor/" data-count="horizontal" data-text="ggedit – interactive ggplot aesthetic and theme editor" 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://www.r-statistics.com/2016/11/ggedit-interactive-ggplot-aesthetic-and-theme-editor/"> R – R-statistics blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><em>Guest post by <strong><a target="_blank" rel="nofollow" href="https://github.com/yonicd">Jonathan Sidi</a>, <a target="_blank" rel="nofollow" href="http://metrumrg.com/opensourcetools.html">Metrum Research Group</a></strong></em></p>
<p><a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/ggplot2/index.html">ggplot2</a> has become the standard of plotting in R for many users. New users, however, may find the learning curve steep at first, and more experienced users may find it challenging to keep track of all the options (especially in the theme!).</p>
<p><a target="_blank" rel="nofollow" href="https://github.com/metrumresearchgroup/ggedit">ggedit</a> is a package that helps users bridge the gap between making a plot and getting all of those pesky plot aesthetics just right, all while keeping everything portable for further research and collaboration.</p>
<p>ggedit is powered by a <a target="_blank" rel="nofollow" href="http://shiny.rstudio.com/">Shiny gadget</a> where the user inputs a ggplot plot object or a list of ggplot objects. You can run ggedit directly from the console from the Addin menu within RStudio.</p>
<div>
<h2>Installation</h2>
<pre><code>devtools::install_github(&quot;metrumresearchgroup/ggedit&quot;,subdir=&quot;ggedit&quot;)</code></pre>
</div>
<div>
<h2>Layers</h2>
<p>The gadget creates a popup window which is populated by the information found in each layer. You can edit the aesthetic values found in a layer and see the changes happen in real time.</p>
<p><iframe height="480" width="450" allowfullscreen="allowfullscreen" src="https://www.youtube.com/embed/OvMWCHpCmaI"><br>
</iframe></p>
<p>You can edit the aesthetic layers while still preserving the original plot, because the changed layers are cloned from the original plot object and are independent of it. The edited layers are provided in the output as objects, so you can use the layers independent of the plot using regular ggplot2 grammar. This is a great advantage when collaborating with other people, where you can send a plot to team members to edit the layers aesthetics and they can send you back just the new layers for you to implement them.</p>
</div>
<div>
<h2>Themes</h2>
<p>ggedit also has a theme editor inside. You can edit any element in the theme and see the changes in real time, making the trial and error process quick and easy. Once you are satisfied with the edited theme you can apply it to other plots in the plot list with one click or even make it the <em>session</em> theme regardless of the gadget. As with layers, the new theme object is part of the output, making collaboration easy.</p>
<p><iframe height="480" width="450" allowfullscreen="allowfullscreen" src="https://www.youtube.com/embed/813QxbsrvLM"><br>
</iframe></p>
</div>
<div>
<h2>Outputs</h2>
<p>The gadget returns a list containing 4 elements</p>
<ul>
<li>updatedPlots
<ul>
<li>List containing updated ggplot objects</li>
</ul>
</li>
<li>updatedLayers
<ul>
<li>For each plot a list of updated layers (ggproto) objects</li>
<li>Portable object</li>
</ul>
</li>
<li>updatedLayersElements
<ul>
<li>For each plot a list elements and their values in each layer</li>
<li>Can be used to update the new values in the original code</li>
</ul>
</li>
<li>updatedThemes
<ul>
<li>For each plot a list of updated theme objects</li>
<li>Portable object</li>
<li>If the user doesn’t edit the theme updatedThemes will not be returned</li>
</ul>
</li>
</ul>
</div>
<div>
<h2>rgg</h2>
<p>After you finish editing the plots the natural progression is to use them in the rest of the script. In ggedit there is the function rgg (remove and replace ggplot). Using this function you can chain into the original code changes to the plot without multiplying script needlessly.</p>
<p><iframe height="480" width="450" allowfullscreen="allowfullscreen" src="https://www.youtube.com/embed/0QmJHwoWQWM"><br>
</iframe></p>
<p>With this function you can</p>
<p>Specify which layer you want to remove from a plot:</p>
<p><code>ggObj%>%rgg('line')</code></p>
<p>Provide an index to a specific layer, in instances where there are more than one layer of the same type in the plot</p>
<p><code>ggObj%>%rgg('line',2)</code></p>
<p>Remove a layer from ggObj and replace it with a new one from the ggedit output p.out</p>
<p><code>ggObj%>%rgg('line',newLayer = p.out$UpdatedLayers)</code></p>
<p>Remove a layer and replace it with a new one and the new theme</p>
<p><code>ggObj%>%rgg('line',newLayer = p.out$UpdatedLayers)+p.out$UpdatedThemes</code></p>
<p>There is also a plotting function for ggedit objects that creates a grid.view for you and finds the best grid size for the amount of plots you have in the list. And for the exotic layouts you can give specific positions and the rest will be done for you. If you didn’t use ggedit, you can still add the class to any ggplot and use the plotting function just the same.</p>
<pre><code>plot(as.ggedit(list(p0,p1,p2,p3)),list(list(rows=1,cols=1:3),
                                       list(rows=2,cols=2),
                                       list(rows=2,cols=1),
                                       list(rows=2,cols=3))
)</code></pre>
</div>
<div>
<h2>Addin Launch</h2>
<p>To launch the Shiny gadget from the addin menu highlight the code that creates the plot object or the plot name in the source pane of Rstudio, then click on the ggedit addin from the Addins the dropdown menu.</p>
<p><iframe height="480" width="450" allowfullscreen="allowfullscreen" src="https://www.youtube.com/embed/693XhHt8fug"><br>
</iframe></p>
<hr>
<p><em> Jonathan Sidi joined Metrum Researcg Group in 2016 after working for several years on problems in applied statistics, financial stress testing and economic forecasting in both industrial and academic settings.</em></p>
<p>To learn more about additional open-source software packages developed by Metrum Research Group please visit the <a target="_blank" rel="nofollow" href="http://metrumrg.com/opensourcetools.html">Metrum website</a>.</p>
<p><span><strong>Contact</strong></span>: For questions and comments, feel free to email me at: <a target="_blank" rel="nofollow" href="mailto:yonis@metrumrg.com">yonis@metrumrg.com</a> or open an issue in <a target="_blank" rel="nofollow" href="https://github.com/metrumresearchgroup/ggedit/issues">github</a>.</p>
</div>
<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/ggedit-interactive-ggplot-aesthetic-and-theme-editor/"></div></div><div><a data-url="https://www.r-bloggers.com/ggedit-interactive-ggplot-aesthetic-and-theme-editor/" data-counturl="https://www.r-bloggers.com/ggedit-interactive-ggplot-aesthetic-and-theme-editor/" data-count="vertical" data-text="ggedit – interactive ggplot aesthetic and theme editor" 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://www.r-statistics.com/2016/11/ggedit-interactive-ggplot-aesthetic-and-theme-editor/"> R – R-statistics blog</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/S_VytZjXA_U"></a></div>