Skip to content

Commit

Permalink
add legend to plot som_evaluate_cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertocamara committed Feb 21, 2025
1 parent dd99d18 commit c83c3b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 6 additions & 1 deletion R/sits_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,7 @@ plot.sits_accuracy <- function(x, y, ..., title = "Confusion matrix") {
#' @param x Object of class "plot.som_evaluate_cluster".
#' @param y Ignored.
#' @param ... Further specifications for \link{plot}.
#' @param legend Legend with colors to be plotted.
#' @param name_cluster Choose the cluster to plot.
#' @param title Title of plot.
#' @return A plot object produced by the ggplot2 package
Expand All @@ -1690,6 +1691,7 @@ plot.sits_accuracy <- function(x, y, ..., title = "Confusion matrix") {
#' @export
#'
plot.som_evaluate_cluster <- function(x, y, ...,
legend = NULL,
name_cluster = NULL,
title = "Confusion by cluster") {
stopifnot(missing(y))
Expand All @@ -1704,11 +1706,14 @@ plot.som_evaluate_cluster <- function(x, y, ...,
data <- dplyr::filter(data, .data[["cluster"]] %in% name_cluster)
}
# configure plot colors
# convert legend from tibble to vector
if (.has(legend))
legend <- .colors_legend_set(legend)
# get labels from cluster table
labels <- unique(data[["class"]])
colors <- .colors_get(
labels = labels,
legend = NULL,
legend = legend,
palette = "Set3",
rev = TRUE
)
Expand Down
11 changes: 10 additions & 1 deletion man/plot.som_evaluate_cluster.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c83c3b0

Please sign in to comment.