afrimapr / afrilearndata

small african spatial datasets for learning & teaching mapping in R
https://afrimapr.github.io/afrilearndata
15 stars 11 forks source link

find a good way of storing colours for categorical afrilandcover raster #8

Open andysouth opened 2 years ago

andysouth commented 2 years ago

I would like the labels and colours for the categorical raster object afrilandcover to be stored in the object so that it is easy for new users to be able to plot them.

The current sub-optimal solution enables this to work in mapview but similar seems not to work in tmap

mapview(afrilandcover, att="landcover", col.regions=levels(afrilandcover)[[1]]$colour)

Here is my unfinished experimentation including trying stars & terra. Ideally I'd like to use stars.

https://github.com/afrimapr/afrilearndata/blob/d8510ed4a732418c4cf1a385867604d341528ad0/data-raw/afrilearndata-data-creation.R#L456

If anyone has a good solution for this I'd be very grateful.