How to display points with NA values geom_sf() or geom_point()

Hello!

I am trying to visualize some spatial data with categories that have some NA values. But I keep getting the warning message telling me that it has removed rows containing missing values.

Warning message:
Removed 7 rows containing missing values (geom_sf).

However, it still shows that there are NA values in the category, but doesn't plot them, as shown below.

I want ggplot to plot the location of those points but assign them to that NA category that has a grey color value. I tried na.rm = F, but that's a default parameter, and I don't see a way to tell it not to remove those points from the plot.

Here is my code:

tp.plot <- ggplot() + 
  geom_sf(data=cb1) +
  geom_sf(data=sf.cat, aes(col=TP_CAT, size=PTL), na.rm=F) +
  labs(title = "Total Phosphorus (PTL, mg/L)")

Where cb1 is an sf of the shoreline and sf.cat is an sf with the data.

Any help would be greatly appreciated.

Thanks so much!

Hey there,

you can add a manual color scale to your plot using scale_color_manual. There you will need to define the factor levels of TP_Cat in breaks, the respective colors in values as well as labels and can also add a na.value color.
See

 ?ggplot2::scale_color_manual

Please let us know whether it worked or not and how your code looked in the end.

Best,
Valentin