title: Creating "wrapper" function for generating location-specific plots
body: <p>I have a section of code which generates plots for particular genetic data when region = x (see example section for region=Central below), however I want to create a &quot;wrapper&quot; function in R for this to reduce the amount of fluff, where if region = x, run a PCA on this regions data, and then generate a plot (pic included). Is there a way to do this smoothly? I am very new to coding so hope this is clear!</p>
  <pre class="lang-r prettyprint-override"><code>Central &lt;- autoplot(pca, data = G5.ID3, colour = 'Region') + scale_color_viridis(discrete=TRUE,option=&quot;D&quot;) +
    gghighlight(Region == &quot;Central Otago&quot;, use_group_by = FALSE, use_direct_label = FALSE, label_key = Region) + 
    theme(legend.position = &quot;none&quot;,
          axis.title.x=element_blank(),
          axis.text.x=element_blank(),
          axis.ticks.x=element_blank(),
          axis.title.y=element_blank(),
          axis.text.y=element_blank(),
          axis.ticks.y=element_blank()) + 
    annotate(geom=&quot;text&quot;, x=-Inf, y=Inf, hjust=-0.1, vjust=1.6, size = 4, label=&quot;Central Otago&quot;)
  </code></pre>
  <p>data for location = Central :<br />
  <a href="https://i.stack.imgur.com/0Lu0o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0Lu0o.png" alt="data for location = Central " /></a></p>