Skip to contents

Plot confusion matrix

Usage

draw_confusion(
  x,
  xlab = "Predicted",
  ylab = "Reference",
  true_col = "#72CDF4",
  false_col = "#FEB2E0",
  font_size = 18,
  main = NULL,
  main_y = 1,
  main_yanchor = "bottom",
  theme = rtemis_theme,
  margin = list(l = 20, r = 5, b = 5, t = 20),
  filename = NULL,
  file_width = 500,
  file_height = 500,
  file_scale = 1,
  ...
)

Arguments

x

ClassificationMetrics object produced by classification_metrics or confusion matrix where rows are the reference and columns are the estimated classes. For binary classification, the first row and column are the positive class.

xlab

Character: x-axis label. Default is "Predicted".

ylab

Character: y-axis label. Default is "Reference".

true_col

Color for true positives & true negatives.

false_col

Color for false positives & false negatives.

font_size

Integer: font size.

main

Character: plot title.

main_y

Numeric: y position of the title.

main_yanchor

Character: y anchor of the title.

theme

List or Character: Either the output of a theme_*() function or the name of a theme. Use themes() to get available theme names. Theme functions are of the form theme_<name>.

margin

List: Plot margins.

filename

Character: file name to save the plot. Default is NULL.

file_width

Numeric: width of the file. Default is 500.

file_height

Numeric: height of the file. Default is 500.

file_scale

Numeric: scale of the file. Default is 1.

...

Additional arguments passed to theme functions.

Value

A plotly object.

Author

EDG

Examples

if (FALSE) { # \dontrun{
# Assume positive class is "b"
true_labels <- factor(c("a", "a", "a", "b", "b", "b", "b", "b", "b", "b"))
predicted_labels <- factor(c("a", "b", "a", "b", "b", "a", "b", "b", "b", "a"))
predicted_prob <- c(0.3, 0.55, 0.45, 0.75, 0.57, 0.3, 0.8, 0.63, 0.62, 0.39)
metrics <- classification_metrics(true_labels, predicted_labels, predicted_prob)
draw_confusion(metrics)
} # }