1

I have just made a plot using raster data that consists of 6 different land types and fit them to polygon vectors. I'm trying to change the values on the continuous scale bar (1-6) to the names of each landtype (e.g. grasslands, urban, etc) which is what each different colour represents. I have tried inserting breaks, however then each box in the legend contains labels (1-2, 2-3, 3-4 etc.) Raster plot where each diff colour represents diff land type

This is my code: rasterxpolygonplotcode

Alex White
  • 21
  • 2
  • A proper question should include a *minimal self-contained reproducible example*, that is, add some data generated by code or that ships with R and show what you tried (and only include code relevant to the question at hand). Please do *not* include screenshots of code. – Robert Hijmans Jul 07 '22 at 14:34

1 Answers1

1

Example data

library(terra)
r <- rast(nrows=10, ncols=10)
values(r) <- sample(3, ncell(r), replace=TRUE)
cover <- c("forest", "water", "urban")

You can either do:

plot(r, type="classes", levels=cover)

Or first make the raster categorical

levels(r) <- data.frame(id=1:3, cover=c("forest", "water", "urban"))
plot(r)
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63