Using dbscan with tidyverse

knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

The dbscan package provides tidy(), augment(), and glance() methods for its clustering algorithms, making them easy to use with tidyverse, ggplot2, and tidymodels.

Load the packages and prepare the numeric variables from the iris data:

library(dbscan)
library(tidyverse)

x <- iris[, 1:4]
db <- x %>% dbscan(eps = .42, minPts = 5)

Get cluster statistics as a tibble:

tidy(db)

Visualize the clustering with ggplot2, using an x for noise points:

augment(db, x) %>%
  ggplot(aes(x = Petal.Length, y = Petal.Width)) +
  geom_point(aes(color = .cluster, shape = noise)) +
  scale_shape_manual(values = c(19, 4))


Try the dbscan package in your browser

Any scripts or data that you put into this service are public.

dbscan documentation built on Oct. 5, 2026, 9:07 a.m.