title: Override aesthetics of custom plot
body: <p>I am not sure exactly how to override aesthetic properties of a custom plot made with ggplot. The only way I could think of right now was using the functionality of the <code>grid</code> package, though is really hackish. Maybe there is a easier way, like using <code>guides</code> or so from <code>ggplot2</code>, though I could't manage to make it work?</p>
  <p>Below is an example where I just want to adjust the line width in the graph. Of course, I would like that to trickle down in the legend as well. So, below are my steps with <code>grid</code>, but any simpler solution is greatly appreciated (ideally something that doesn't need <code>grid</code> but just <code>ggplot2</code>, if possible).</p>
  
  <pre class="lang-r prettyprint-override"><code>library(iNEXT)
  library(ggplot2)
  library(grid)
  
  # Some custom plot from the iNEXT package
  data(spider)
  out &lt;- iNEXT(spider, q=0, datatype=&quot;abundance&quot;)
  
  custom_plot &lt;- ggiNEXT(out)
  custom_plot
  </code></pre>
  <p><img src="https://i.imgur.com/ehmfBZc.png" alt="" /></p>
  <pre class="lang-r prettyprint-override"><code># Get the grobs
  g &lt;- grid.force(ggplotGrob(custom_plot))
  
  # Check the list of names of grobs:
  # grid.ls(g) 
  # View(g$grobs)
  
  # Get an idea about the grob paths
  gpaths &lt;- paste(gsub(pattern = &quot;layout::&quot;, 
                       replacement = &quot;&quot;, 
                       x = grid.ls(g, print = FALSE)$gPath), 
                  grid.ls(g, print = FALSE)$name, 
                  sep = &quot;::&quot;)
  gpaths[grepl(&quot;polyline&quot;, gpaths)]
  #&gt; [1] &quot;panel.7-5-7-5::grill.gTree.114::panel.grid.minor.y..polyline.107&quot;            
  #&gt; [2] &quot;panel.7-5-7-5::grill.gTree.114::panel.grid.minor.x..polyline.109&quot;            
  #&gt; [3] &quot;panel.7-5-7-5::grill.gTree.114::panel.grid.major.y..polyline.111&quot;            
  #&gt; [4] &quot;panel.7-5-7-5::grill.gTree.114::panel.grid.major.x..polyline.113&quot;            
  #&gt; [5] &quot;panel.7-5-7-5::GRID.polyline.91&quot;                                             
  #&gt; [6] &quot;panel.7-5-7-5::geom_ribbon.gTree.101::geom_ribbon.gTree.95::GRID.polyline.93&quot;
  #&gt; [7] &quot;panel.7-5-7-5::geom_ribbon.gTree.101::geom_ribbon.gTree.99::GRID.polyline.97&quot;
  
  # Edit the width of the lines
  g &lt;- editGrob(grob = g, 
                gPath = gpaths[grepl(&quot;panel.7-5-7-5::GRID.polyline&quot;, gpaths)],
                gp = gpar(lwd = c(1,1,1,1)))
  plot(g)
  </code></pre>
  <p><img src="https://i.imgur.com/mERhdHn.png" alt="" /></p>
  <p><sup>Created on 2020-07-22 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.3.0)</sup></p>