I have a contour dataset imported using st_read() from a shapefile. I have plotted this using ggplot() and geom_sf(). It renders nicely. Now I want to label the contours. Using geom_st_label() does not produce great output. Contours are dense in places and labels overlap.
I had a look at the metR package. This has a geom_contour_label() function that controls contour placement nicely in ggplot(). However, the geom_contour() and associated functions do not recognise the geometry contained in sf_objects. I get this error: stat_contour requires the following missing aesthetics: x, y and z.
How can I get geom_contour_label() to work with an sf object? This is what geom_contour_label() can produce:
My contour data is available from https://cloudstor.aarnet.edu.au/sender/?s=download&token=241de91b-2015-4a19-a18f-c2125a12f2a7.
library(sf)
library(tidyverse)
isobath <- read_sf("1misobath.shp")
ggplot() +
geom_sf(data = isobath, color = "blue", lwd = 0.25) +
geom_sf_label(data = isobath, aes(label = DEPTH), size = 2) +
coord_sf(xlim = c(18.42, 18.5), ylim = c(-34.20, -34.16), expand = T) +
theme_bw()


