<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-0-0-2-a-gui-for-advanced-editing-of-ggplot2-objects/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.r-statistics.com/2017/01/ggedit-0-0-2-a-gui-for-advanced-editing-of-ggplot2-objects/"> R – R-statistics blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h4>Guest post by <em><a target="_blank" rel="nofollow" href="https://twitter.com/yoniceedee">Jonathan Sidi</a>, <a target="_blank" rel="nofollow" href="http://metrumrg.com/opensourcetools.html">Metrum Research Group</a></em></h4>
<p>Last week the updated version of <a target="_blank" rel="nofollow" href="https://github.com/metrumresearchgroup/ggedit">ggedit</a> was presented in <a target="_blank" rel="nofollow" href="https://www.rstudio.com/conference/">RStudio::conf2017</a>. First, a BIG thank you to the whole RStudio team for a great conference and being so awesome to answer the insane amount of questions I had (sorry!). For a quick intro to the package see the <a target="_blank" rel="nofollow" href="https://www.r-statistics.com/2016/11/ggedit-interactive-ggplot-aesthetic-and-theme-editor/">previous post</a>.</p>
<p>To install the package:</p>
<p><code>devtools::install_github(&quot;metrumresearchgroup/ggedit&quot;,subdir=&quot;ggedit&quot;)</code></p>
<div>
<h1>Highlights of the updated version.</h1>
<ul>
<li>verbose script handling during updating in the gagdet (see video below)</li>
<li>verbose script output for updated layers and theme to parse and evaluate in console or editor</li>
<li>colourpicker control for both single colours/fills and and palletes</li>
<li>output for scale objects eg scale*grandient,scale*grandientn and scale*manual</li>
<li>verbose script output for scales eg scale*grandient,scale*grandientn and scale*manual to parse and evaluate in console or editor</li>
<li>input plot objects can have the data in the layer object and in the base object.
<ul>
<li><code>ggplot(data=iris,aes(x=Sepal.Width,y=Sepal.Length,colour=Species))+geom_point()</code></li>
<li><code>ggplot(data=iris,aes(x=Sepal.Width,y=Sepal.Length))+geom_point(aes(colour=Species))</code></li>
<li><code>ggplot()+geom_point(data=iris,aes(x=Sepal.Width,y=Sepal.Length,colour=Species))</code></li>
</ul>
</li>
<li>plot.theme(): S3 method for class ‘theme’
<ul>
<li>visualizing theme objects in single output</li>
<li>visual comparison of two themes objects in single output</li>
<li>will be expanded upon in upcoming post</li>
</ul>
</li>
</ul>
<p></p>
<p><iframe height="342" width="456" allowfullscreen src="https://www.youtube.com/embed/LN5OzswgUY4?feature=oembed"></iframe></p>
<div>
<h1>RStudio::conf2017 Presentation</h1>
<pre><code>#devtools::install_github(&quot;metrumresearchgroup/ggedit&quot;,subdir=&quot;ggedit&quot;)
rm(list=ls())
library(ggedit)
#?ggedit

p0=list(
  Scatter=iris%>%ggplot(aes(x =Sepal.Length,y=Sepal.Width))+
    geom_point(aes(colour=Species),size=6),
  
  ScatterFacet=iris%>%ggplot(aes(x =Sepal.Length,y=Sepal.Width))+
    geom_point(aes(colour=Species),size=6)+
      geom_line(linetype=2)+
    facet_wrap(~Species,scales='free')+
    labs(title='Some Title')
  )

#a=ggedit(p.in = p0,verbose = T) #run ggedit
dat_url &lt;- paste0(&quot;https://raw.githubusercontent.com/metrumresearchgroup/ggedit/master/RstudioExampleObj.rda&quot;)
load(url(dat_url)) #pre-run example

ldply(a,names)</code></pre>
<pre><code>##                     .id      V1           V2
## 1          UpdatedPlots Scatter ScatterFacet
## 2         UpdatedLayers Scatter ScatterFacet
## 3 UpdatedLayersElements Scatter ScatterFacet
## 4     UpdatedLayerCalls Scatter ScatterFacet
## 5         updatedScales Scatter ScatterFacet
## 6    UpdatedScalesCalls Scatter ScatterFacet
## 7         UpdatedThemes Scatter ScatterFacet
## 8     UpdatedThemeCalls Scatter ScatterFacet</code></pre>
<pre><code>plot(a)</code></pre>
<p><img src="https://i0.wp.com/raw.githubusercontent.com/metrumresearchgroup/ggedit/master/RstudioConf/Figs/unnamed-chunk-1-1.png?w=840&ssl=1" data-recalc-dims="1"></p>
<pre><code>comparePlots=c(p0,a$UpdatedPlots)
names(comparePlots)[c(3:4)]=paste0(names(comparePlots)[c(3:4)],&quot;Updated&quot;)</code></pre>
</div>
<div>
<h1>Initial Comparison Plot</h1>
<pre><code>plot(as.ggedit(comparePlots))</code></pre>
<p><img src="https://i2.wp.com/raw.githubusercontent.com/metrumresearchgroup/ggedit/master/RstudioConf/Figs/unnamed-chunk-2-1.png?w=840&ssl=1" data-recalc-dims="1"></p>
</div>
<div>
<h1>Apply updated theme of first plot to second plot</h1>
<pre><code>comparePlots$ScatterFacetNewTheme=p0$ScatterFacet+a$UpdatedThemes$Scatter

plot(as.ggedit(comparePlots[c(&quot;ScatterFacet&quot;,&quot;ScatterFacetNewTheme&quot;)]),
      plot.layout = list(list(rows=1,cols=1),list(rows=2,cols=1))
     )</code></pre>
<p><img src="https://i0.wp.com/raw.githubusercontent.com/metrumresearchgroup/ggedit/master/RstudioConf/Figs/unnamed-chunk-3-1.png?w=840&ssl=1" data-recalc-dims="1"> #Using Remove and Replace Function ##Overlay two layers of same geom</p>
<pre><code>(comparePlots$ScatterMistake=p0$Scatter+a$UpdatedLayers$ScatterFacet[[1]])</code></pre>
<p><img src="https://i1.wp.com/raw.githubusercontent.com/metrumresearchgroup/ggedit/master/RstudioConf/Figs/unnamed-chunk-4-1.png?w=840&ssl=1" data-recalc-dims="1"></p>
<div>
<h2>Remove</h2>
<pre><code>(comparePlots$ScatterNoLayer=p0$Scatter%>%
  rgg(oldGeom = 'point'))</code></pre>
<p><img src="https://i0.wp.com/raw.githubusercontent.com/metrumresearchgroup/ggedit/master/RstudioConf/Figs/unnamed-chunk-5-1.png?w=840&ssl=1" data-recalc-dims="1"></p>
</div>
<div>
<h2>Replace Geom_Point layer on Scatter Plot</h2>
<pre><code>(comparePlots$ScatterNewLayer=p0$Scatter%>%
  rgg(oldGeom = 'point',
      oldGeomIdx = 1,
      newLayer = a$UpdatedLayers$ScatterFacet[[1]]))</code></pre>
<p><img src="https://i1.wp.com/raw.githubusercontent.com/metrumresearchgroup/ggedit/master/RstudioConf/Figs/unnamed-chunk-6-1.png?w=840&ssl=1" data-recalc-dims="1"></p>
</div>
<div>
<h2>Remove and Replace Geom_Point layer and add the new theme</h2>
<pre><code>(comparePlots$ScatterNewLayerTheme=p0$Scatter%>%
  rgg(oldGeom = 'point',
      newLayer = a$UpdatedLayers$ScatterFacet[[1]])+
  a$UpdatedThemes$Scatter)</code></pre>
<p><img src="https://i2.wp.com/raw.githubusercontent.com/metrumresearchgroup/ggedit/master/RstudioConf/Figs/unnamed-chunk-7-1.png?w=840&ssl=1" data-recalc-dims="1"></p>
</div>
</div>
<div>
<h1>Cloning Layers</h1>
<div>
<h2>A geom_point layer</h2>
<pre><code>(l=p0$Scatter$layers[[1]])</code></pre>
<pre><code>## mapping: colour = Species 
## geom_point: na.rm = FALSE
## stat_identity: na.rm = FALSE
## position_identity</code></pre>
</div>
<div>
<h2>Clone the layer</h2>
<pre><code>(l1=cloneLayer(l))</code></pre>
<pre><code>## mapping: colour = Species 
## geom_point: na.rm = FALSE
## stat_identity: na.rm = FALSE
## position_identity</code></pre>
<pre><code>all.equal(l,l1)</code></pre>
<pre><code>## [1] TRUE</code></pre>
</div>
</div>
<div>
<h2>Verbose copy of layer</h2>
<pre><code>(l1.txt=cloneLayer(l,verbose = T))</code></pre>
<pre><code>## [1] &quot;geom_point(mapping=aes(colour=Species),na.rm=FALSE,size=6,data=NULL,position=\&quot;identity\&quot;,stat=\&quot;identity\&quot;,show.legend=NA,inherit.aes=TRUE)&quot;</code></pre>
<div>
<h3>Parse the text</h3>
<pre><code>(l2=eval(parse(text=l1.txt)))</code></pre>
<pre><code>## mapping: colour = Species 
## geom_point: na.rm = FALSE
## stat_identity: na.rm = FALSE
## position_identity</code></pre>
</div>
<pre><code>all.equal(l,l2)</code></pre>
<pre><code>## [1] TRUE</code></pre>
</div>
<div>
<h2>Back to our example</h2>
<pre><code>  #Original geom_point layer
  parse(text=cloneLayer(p0$ScatterFacet$layers[[1]],verbose = T))</code></pre>
<pre><code>## expression(geom_point(mapping = aes(colour = Species), na.rm = FALSE, 
##     size = 6, data = NULL, position = &quot;identity&quot;, stat = &quot;identity&quot;, 
##     show.legend = NA, inherit.aes = TRUE))</code></pre>
<pre><code>  #new Layer
  parse(text=a$UpdatedLayerCalls$ScatterFacet[[1]])</code></pre>
<pre><code>## expression(geom_point(mapping = aes(colour = Species), na.rm = FALSE, 
##     size = 3, shape = 22, fill = &quot;#BD2020&quot;, alpha = 1, stroke = 0.5, 
##     data = NULL, position = &quot;identity&quot;, stat = &quot;identity&quot;, show.legend = NA, 
##     inherit.aes = TRUE))</code></pre>
</div>
<p></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 Metrum <a target="_blank" rel="nofollow" href="http://metrumrg.com/opensourcetools.html">website</a>.</p>
<p>Contact: 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>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/2017/01/ggedit-0-0-2-a-gui-for-advanced-editing-of-ggplot2-objects/"> 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/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/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/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/PbeB0S7N83s"></a></div>