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

show_landscape coloring bug with ratified raster #28

Open
nldoc opened this issue Apr 27, 2020 · 0 comments
Open

show_landscape coloring bug with ratified raster #28

nldoc opened this issue Apr 27, 2020 · 0 comments

Comments

@nldoc
Copy link

nldoc commented Apr 27, 2020

I have just noticed a potential bug, when show_landscape() is used for a raster with classes defined by ratify(). Please see the reproducible example below:

Lets first look at the default map directly, without classification trough ratify():

show_landscape(landscapetools::classified_landscape, discrete=TRUE)

grafik

Now we classify the three land uses with different names, and execute show_landscape() with the default (wrong!) color scale:

# Ratify raster and define 3 example class names for landuse 1, 2 and 3:
ls <- raster::ratify(landscapetools::classified_landscape)
levels(ls)[[1]] = cbind(levels(ls)[[1]], 
                        c("Land Use 1" = "Bare (lu1)", "Land Use 2" = "Rainforest (lu2)", "Land Use 3" = "Agriculture (lu3)"))

# Show landscape with default (wrong!) fill scale:
show_landscape(ls, discrete=TRUE)

This produces the following map:
grafik
you can already see, that the legend order is the same if you look at the numbers in the brackets, which were the original land use numbers, but the coloring of the patches changed on the map.
Now we overwrite the default fill scale from show_landscape():

# Show landscape with overwritten (correct!) fill scale:
show_landscape(ls, discrete=TRUE) +
  scale_fill_viridis_d()

This produces the following map which has the correct legend order:
grafik

I assume, the error is due to the order of factors, where the ratify levels are defined.
Cheers, nldoc

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

1 participant