Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panel plots with categorical rasters #1143

Closed
jflowernet opened this issue May 4, 2023 · 2 comments
Closed

Panel plots with categorical rasters #1143

jflowernet opened this issue May 4, 2023 · 2 comments

Comments

@jflowernet
Copy link

When plotting multi-layer categorical rasters, it would be nice to be able to plot them with a single, common legend. panel() does not seem to accept categorical rasters so it appears there is no way to do this at the moment? Any chance this option could be implemented in the future?

library(terra)
#> terra 1.7.29

r <- rast(nrows=5, ncols=9)
values(r) <- sample(3, ncell(r), replace = TRUE)
x <- c(r, r, r)

levels_df <- data.frame(id=1:3, type = c("river", "land", "ocean"))

levels(x) <- list(levels_df, levels_df, levels_df)

plot(x)

panel(x)
#> Error: [panel] cannot use categorical rasters

Created on 2023-05-04 with reprex v2.0.2

@rhijmans
Copy link
Member

rhijmans commented May 4, 2023

That is a bit more tricky because the levels need to match, or at least not conflict, but this now works for your example.

@jflowernet
Copy link
Author

Excellent! Many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants