title: Customize breaks on a color gradient legend using base R
body: <p>Here is a sample script using random numbers instead of real elevation data.</p>
  
  <pre><code>library(gridExtra)
  library(spatstat) #im function
  
  elevation &lt;- runif(500, 0, 10)
  B &lt;- matrix(elevation, nrow = 20, ncol = 25)
  Elevation_Map &lt;- im(B)
  custom &lt;- colorRampPalette(c("cyan","green", "yellow", "orange", "red"))
  plot(Elevation_Map, col = custom(10), main = NULL)
  </code></pre>
  
  <p>This is the plot and legend that I get:</p>
  
  <p><a href="https://i.stack.imgur.com/DbpGr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DbpGr.png" alt="enter image description here"></a></p>
  
  <p>This is the legend that I am trying to recreate in R (this one made in Word):</p>
  
  <p><a href="https://i.stack.imgur.com/pEnWp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pEnWp.png" alt="enter image description here"></a></p>
  
  <p>I know this is possible and its probably a simple solution but I've tried using some examples I found online to no avail.</p>
  
  <p>This plot (with real elevation data) is an art piece that will be hung in a gallery, with the elevation plot on 1 board and the legend on a separate board. I tried to get R to plot just the plot without the legend using</p>
  
  <pre><code>plot(Elevation_Map, col = custom(10), main = NULL, legend = NULL)
  </code></pre>
  
  <p>like I have in the past but for some reason it always plots the legend with the plot. As of right now I'm planning on just cropping the .pdf into 2 separate files to achieve this.</p>