Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
LudvigOlsen committed Feb 17, 2021
2 parents 380dc22 + 551688b commit ab3d5c8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: cvms
Title: Cross-Validation for Model Selection
Version: 1.2.0.9000
Version: 1.2.1
Authors@R:
c(person(given = "Ludvig Renbo",
family = "Olsen",
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

# cvms 1.2.0.9000
# cvms 1.2.1

* Fixes bug in `plot_confusion_matrix()`, where tiles with a count > 0 but a rounded percentage of 0 did not have the percentage text. Only tiles with a count of 0 should now be without text.

# cvms 1.2.0

Expand Down
7 changes: 6 additions & 1 deletion R/plot_confusion_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,12 @@ plot_confusion_matrix <- function(conf_matrix,

# Prepare text versions of the numerics
cm[["N_text"]] <- preprocess_numeric(cm[["N"]], font_counts, rm_zero_text = rm_zero_text)
cm[["Normalized_text"]] <- preprocess_numeric(cm[["Normalized"]], font_normalized, rm_zero_text = rm_zero_text)
cm[["Normalized_text"]] <- preprocess_numeric(
cm[["Normalized"]],
font_normalized,
rm_zero_text = rm_zero_text,
rm_zeroes_post_rounding = FALSE # Only remove where N==0
)

# Set color intensity metric
cm <- set_intensity(cm, intensity_by)
Expand Down
15 changes: 13 additions & 2 deletions R/plotting_utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,25 @@ update_font_setting <- function(settings, defaults, initial_vals = NULL) {
)
}

preprocess_numeric <- function(vec, settings, rm_zero_text=FALSE) {
preprocess_numeric <- function(vec, settings, rm_zero_text=FALSE, rm_zeroes_post_rounding=TRUE) {

# Find the pre-rounding 0s
is_zero <- vec == 0

# Don't round if digits is negative
if (settings[["digits"]] >= 0) {
vec <- round(vec, settings[["digits"]])
}
out <- paste0(settings[["prefix"]], vec, settings[["suffix"]])

# Remove text for zeroes
# Potentially including elements zero after rounding
if (isTRUE(rm_zero_text)){
out[vec == 0] <- ""
if (isTRUE(rm_zeroes_post_rounding)){
out[vec == 0] <- ""
} else {
out[is_zero] <- ""
}
}
out
}
Expand Down

0 comments on commit ab3d5c8

Please sign in to comment.