A tile heatmap of predicted vs actual classes, shaded by row-normalized rate and annotated with counts, so class imbalance does not hide errors.
geom_confusion_matrix(
mapping = NULL,
data = NULL,
normalize = "row",
label_size = NULL
)Standard layer overrides. Map the predicted class to
x, the actual class to y. Provide counts via size, or pass raw
per-observation rows and let the stat count them.
"row" (default), "col", "all", or "none" —
which total the shading is relative to.
Annotation size in px.
A Layer to add with +.
d <- data.frame(
predicted = c("cat", "cat", "dog", "dog", "dog", "cat"),
actual = c("cat", "dog", "dog", "dog", "cat", "cat")
)
ggnext(d, aes(predicted, actual)) + geom_confusion_matrix()
#> <ggnext plot>
#> data: 6 x 2
#> aes: x = predicted, y = actual
#> layers: 1
#> coord: cartesian
#> mode: static