I am doing a tutorial right now on raster data in R and the tutorial says that we can set “bad data” (data that falls outside of the applicable range of a dataset) to a different color, so we can depict the bad data on the plot better.
Below is a screenshot of my code. I have an obj called “DSM_HARV” which I made from converting my raw data (I took out the file path for the below screenshots) into a data frame I can now work with/plot.
After converting the data, I use ‘ggplot’ to plot this raster data using ‘geom_raster()’. The next line is where my question comes into play – the tutorial shows me how to use a color blind pattern to represent the data using the ‘scale_fill_viridis_c()’ function. How can I add to this code that I want any values from the “HARV_dsmCrop” column that are GREATER THAN 400m to be displayed in red on the plot?
enter image description here
enter image description here
I tried using the ‘mutate()’ function, but it did not work. Is there a way I can use the ‘if()’ and just say that- if(HARV_dsmCrop > 400) {color = “red”}? Or do I need to use the ‘group_by()’ and group the values greater than 400?
kronxy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.