# NOT RUN {
library(scapesClassification)
library(terra)
## CREATE A DUMMY RASTER ##
r <- terra::rast(matrix(c(NA,100,100,NA,100,100,0,0,0),
nrow = 3,
ncol = 3,
byrow = TRUE))
## RASTER CELL NUMBERS ##
rcn <- r; rcn[] <- 1:9
## PLOT DATA AND CELL NUMBERS ##
oldpar <- par(mfrow = c(1,2))
m <- c(4, 1, 4, 1)
plot(r, col="grey90", colNA="red3", mar=m, asp = NA, axes=FALSE, legend=FALSE)
text(r)
lines(r)
mtext(side=3, line=0.2, adj=0, cex=1.5, font=2, "Dummy_var")
legend("bottomright", ncol=1, bg="white", fill=c("red3"),
legend = c("NA cells (1 and 4)"))
plot(rcn, col="grey90", mar=m, asp=NA, axes=FALSE, legend=FALSE)
text(rcn)
lines(rcn)
mtext(side=3, line=0.2, adj=0, cex=1.5, font=2, "Cell numbers")
par(oldpar)
## VISUALIZE ATTRIBUTE TABLE ##
at <- attTbl(r, var_names = c("dummy_var"))
at
# Note that cells 1 and 4 have missing values and therefore are not included in the table
any(at$Cell %in% c(1,4))
# }
Run the code above in your browser using DataLab