It's ugly, but you can use plot
for the map and image.plot
for your legend. You will need to add the labels of your custom breaks to the position of the equally spaced breaks.
Plot map without legend:
library(raster)
r <- raster(ncol=5, nrow=4)
r[] <- 1:20
my_breaks = c(0,1,2,3,5,10,20)
n = 6
my_col = rainbow(n)
plot(r, breaks = my_breaks, col = my_col, legend = FALSE, zlim=c(0,20))
The default breaks will be equally spaced from 0 to 20:
def_breaks = seq(0,20,length.out=(n+1))
Add legend using image.plot
from the fields
package, placing custom break labels at default break positions:
library(fields)
image.plot(r, zlim = c(0,20),
legend.only = TRUE,
col = my_col,
axis.args = list(at = def_breaks, labels = my_breaks))