confusion matrix plot

Hi everybody!
Using the iris dataset in R, I write a function to plot a confusion matrix.

library(e1071)
library(caTools)
library(caret)

iris$spl = sample.split(iris, SplitRatio = 0.1)
train <- subset(iris, iris$spl == TRUE)
test <- subset(iris, iris$spl == FALSE)

iris.nb <- naiveBayes(Species ~ ., data = train)

nb_train_predict <- predict(iris.nb, test[ , names(test) != "Species"])

cfm <- confusionMatrix(nb_train_predict, test$Species)
cfm

#ggplot confusion matrix
library(ggplot2)
library(scales)

ggplotConfusionMatrix <- function(m){
  mytitle <- paste("Accuracy", percent_format()(m$overall[1]),
                   "Kappa", percent_format()(m$overall[2]))
  p <-
    ggplot(data = as.data.frame(m$table) ,
           aes(x = Reference, y = Prediction)) +
    geom_tile(aes(fill = log(Freq)), colour = "white") +
    scale_fill_gradient(low = "white", high = "steelblue") +
    geom_text(aes(x = Reference, y = Prediction, label = Freq)) +
    theme(legend.position = "none") +
    ggtitle(mytitle)
  return(p)
}

ggplotConfusionMatrix(cfm)

My question is: How can I remove the "0" from the matrix? (I would like the gray squares without anything written)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.