title: Access and modify elements inside a ggplot object
body: <p>I am testing the diffEnrich package and specifically I would like to modify the legend titles found in Figure 2 of the documentation:
  <a href="https://cran.r-project.org/web/packages/diffEnrich/vignettes/diffenrich_vignette.html" rel="nofollow noreferrer">https://cran.r-project.org/web/packages/diffEnrich/vignettes/diffenrich_vignette.html</a></p>
  <p>eventually aiming to modify the expressions &quot;List 1&quot; and &quot;List 2&quot; to sth more relevant, like &quot;Upregulated&quot; and &quot;Downregulated&quot;, respectively.
  I 've tried grep to locate the expressions of interest in a couple of ways, but all attempts return the same error (mentioned below).</p>
  <p>Assuming a function that produces a ggplot, how can someone find and modify the legend title from within the object?</p>
  <pre><code>v &lt;- ggplot(mtcars) + geom_point(aes(x=disp, y=hp, color=wt)) + 
                        geom_smooth(aes(x=disp, y=hp, color=wt))+ 
                        theme(plot.title=element_text(size=30, face=&quot;bold&quot;), 
                             axis.text.x=element_text(size=15), 
                             axis.text.y=element_text(size=15),
                             axis.title.x=element_text(size=15),
                             axis.title.y=element_text(size=15)) + 
                        scale_color_continuous(name=&quot;Example plot&quot;)
  </code></pre>
  <p>All of the below attempts to locate the legend result in the same error</p>
  <pre><code>lapply(v,function(x) grep(&quot;Example&quot;,x))
  mapply(grep,&quot;Example&quot;,v)
  
  #or
  d &lt;- ggplot_build(v)
  
  lapply(d,function(x) grep(&quot;Example&quot;,x))
  mapply(grep,'Example',d)
  </code></pre>
  <pre><code>Error in as.vector(x, &quot;character&quot;) : 
    cannot coerce type 'environment' to vector of type 'character'
  </code></pre>
  <p>I appreciate your kind solutions.</p>