I am trying to create a map displaying the probability a species will occur in x location the data was in raster format and I converted it into a dataframe. It is on a global scale and I created a lovely ggplot with a gradient scale using the following code:
And this all worked fine!
I then wanted to categorise the probability and did so using the following code:
df$category[df$MAP < 0.05] <- "Absent"
df$category[df$MAP > 0.05 & df$MAP < 0.5] <- "Low probability of presence"
df$category[df$MAP > 0.5] <- "High probability of presence"
this also worked!
But trying to plot this new categorised data onto a map proved a lot more difficult, does anyone have any suggestions?
I couldn't work out which scale function to use from ggplot or how to even format one for discrete data!
To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:
More as a comment than answer; {ggplot2} works fine with vector data, and the geom_sf() is joy to use.
But ggplot2 doesn't like raster data. Base plot via {raster} and / or tm_raster() from {tmap} are often easier choices for convincing raster data visualization.