Skip to content

Commit

Permalink
added categorization error
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Feb 1, 2024
1 parent 6537684 commit 8dc041b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/tmapScaleCategorical.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ tmapScaleCategorical = function(x1, scale, legend, o, aes, layer, layer_args, so
# cast to factor if needed
if (!is.factor(x1)) {
su = sort(unique(x1))
x1 = tryCatch({
factor(x1, levels=su)
}, error = function(e) {
stop("tm_scale_categorical in layer \"tm_", layer, "\", visual variable \"", aes, "\" cannot be applied due to an error categorization of the data", call. = FALSE)
})

x1 = factor(x1, levels=su)
if (is.numeric(su)) levels(x1) <- do.call("fancy_breaks", c(list(vec=su, intervals=FALSE, as.count = FALSE), label.format))
}

Expand Down

0 comments on commit 8dc041b

Please sign in to comment.