r – ggplot – geom_raster scale_fill_identity

I’m kinda stuck in a matter.
Following the advice of another fellow user in this platform, I was able to plot a raster image and have the pixel assume the values I had assigned I a column, named “colors” in my df.

That was great, but know I need the legends assum the categories I have created in another column. So far, my code and my out put look like this

ggplot(data = Xinjiang_df) + geom_raster(aes(x = x, y = y, fill = colors))+  scale_fill_identity(guide = "legend")

Output

enter image description here

I appreciate any suggestion. Thanks.

Read more here: Source link