I made a confusion matrix with cvms plot_confusion_matrix in R. I would like the color intensity of each tile represent the row percentage instead of the counts. In plot_confusion_matrix you can change the color intensity using the intensity_by option. However, row percentages can not be used here. Are there any other options how to solve this? If not is it possible to recreate this plot in ggplot in such a way that it is (almost) similar with rowpercentages as color intensity?
I have made the following dummy code:
library(tidyverse)
library(cvms)
data(iris)
# Create a new categorical variable with 4 classes
set.seed(123) # For reproducibility
new_factor <- factor(sample(c("Class1", "Class2", "Class3", "Class4"), nrow(iris), replace = TRUE))
# Add this new categorical variable to the iris dataset
iris_new <- cbind(iris, New_Categorical_Var = new_factor)
subs_all <- iris_new %>% select(Species, New_Categorical_Var)
subs_all$Species <- factor(subs_all$Species)
subs_all$New_Categorical_Var <- factor(subs_all$New_Categorical_Var)
tbl_all <- table(subs_all)
cfm_all <- as.tibble(tbl_all)
plot_confusion_matrix(cfm_all,
target_col = "Species" ,
prediction_col = "New_Categorical_Var" ,
counts_col = "n")
Based on your question, I added the option to set intensity_by='row_percentages'
and 'col_percentages'
to cvms::plot_confusion_matrix
in v1.7.0. Note that a separate intensity measure must be used for sum tiles (when add_sums=TRUE
) as described in the docs.
I recommend also making future requests for cvms
in an issue on GitHub, since I rarely see these stackoverflow questions: https://github.com/LudvigOlsen/cvms/issues