So I have "punkty" data which has Lat, Long and geometry, "punkty2" data which is just Lat and Long. And a shapefile "osiedla".
I need to make cluster of the data using optics, dbscan and hdbscan from the dbscan package and show the clusters on the "osiedla" map.
I coded that:
db <- dbscan(punkty2, eps = 0.002, minPts = 3)
ggplot() +
geom_sf(data = osiedla, fill = "gray95", color = "grey45") +
geom_sf(data = punkty, color = db$cluster+1, alpha = .7) +
theme_bw()
hdb <- hdbscan(punkty2, minPts = 15)
ggplot() +
geom_sf(data = osiedla, fill = "gray95", color = "grey45") +
geom_sf(data = punkty, color = hdb$cluster+1, alpha = .7) +
theme_bw()
o <- optics(punkty2, eps = 0.002, minPts = 3)
ggplot() +
geom_sf(data = osiedla, fill = "gray95", color = "grey45") +
geom_sf(data = punkty, color = o$cluster+1, alpha = .7) +
theme_bw()
And the first two work no problem, but the last one does not. It says:
Error in geom_sf()
:
! Problem while setting up geom aesthetics.
i Error occurred in the 2nd layer.
Caused by error in check_aesthetics()
:
! Aesthetics must be either length 1 or the same as the data (2000)
x Fix the following mappings: colour
What's wrong?