|
523 | 523 | }
|
524 | 524 | }
|
525 | 525 |
|
526 |
| -.mlClusteringPlotMeans <- function(dataset, options, jaspResults, ready, position) { |
| 526 | +.mlClusteringPlotMeans <- function(dataset, options, jaspResults, ready, position, type) { |
527 | 527 | if (!is.null(jaspResults[["clusterMeans"]]) || !options[["clusterMeanPlot"]]) {
|
528 | 528 | return()
|
529 | 529 | }
|
|
536 | 536 | }
|
537 | 537 | clusterDataset <- data.frame(dataset[, options[["predictors"]], drop = FALSE])
|
538 | 538 | clusterResult <- jaspResults[["clusterResult"]]$object
|
| 539 | + predictions <- clusterResult[["pred.values"]] |
| 540 | + ncolors <- clusterResult[["clusters"]] |
| 541 | + if (type == "densitybased") { |
| 542 | + ncolors <- ncolors + 1 |
| 543 | + predictions[predictions == 0] <- gettext("Noisepoint") |
| 544 | + } |
| 545 | + clusters <- as.factor(predictions) |
539 | 546 | if (options[["clusterMeanPlotSingleFigure"]]) {
|
540 |
| - clusters <- as.factor(clusterResult[["pred.values"]]) |
541 | 547 | xBreaks <- c(1, (as.numeric(levels(clusters)) + 1) * length(options[["predictors"]]))
|
542 | 548 | clusterMeansData <- aggregate(clusterDataset, list(clusters), mean)
|
543 | 549 | clusterSdData <- aggregate(clusterDataset, list(clusters), sd)
|
|
578 | 584 | }
|
579 | 585 | p <- p + ggplot2::scale_x_continuous(name = NULL, breaks = xBreaks, labels = xLabels) +
|
580 | 586 | ggplot2::scale_y_continuous(name = gettext("Cluster Mean"), breaks = yBreaks, limits = range(yBreaks)) +
|
581 |
| - ggplot2::scale_fill_manual(name = gettext("Cluster"), values = .mlColorScheme(length(unique(clusterResult[["pred.values"]])))) + |
| 587 | + ggplot2::scale_fill_manual(name = gettext("Cluster"), values = .mlColorScheme(ncolors)) + |
582 | 588 | jaspGraphs::geom_rangeframe(sides = "l") +
|
583 | 589 | jaspGraphs::themeJaspRaw(legend.position = "right") +
|
584 | 590 | ggplot2::theme(axis.ticks.x = ggplot2::element_blank(), axis.text.x = ggplot2::element_text(angle = 20))
|
585 | 591 | plot[["oneFigure"]] <- createJaspPlot(plot = p, title = gettext("All Features"), height = 400, width = 200 * length(options[["predictors"]]))
|
586 | 592 | } else {
|
587 | 593 | for (variable in unlist(options[["predictors"]])) {
|
588 |
| - clusters <- as.factor(clusterResult[["pred.values"]]) |
589 | 594 | xBreaks <- as.numeric(levels(clusters))
|
590 | 595 | clusterMeansData <- aggregate(clusterDataset[[variable]], list(clusters), mean)
|
591 | 596 | clusterSdData <- aggregate(clusterDataset[[variable]], list(clusters), sd)
|
|
608 | 613 | }
|
609 | 614 | p <- p + ggplot2::scale_x_discrete(name = gettext("Cluster"), breaks = xBreaks) +
|
610 | 615 | ggplot2::scale_y_continuous(name = variable, breaks = yBreaks, limits = range(yBreaks)) +
|
611 |
| - ggplot2::scale_fill_manual(name = gettext("Cluster"), values = .mlColorScheme(length(unique(clusterResult[["pred.values"]])))) + |
| 616 | + ggplot2::scale_fill_manual(name = gettext("Cluster"), values = .mlColorScheme(ncolors)) + |
612 | 617 | jaspGraphs::geom_rangeframe(sides = "l") +
|
613 | 618 | jaspGraphs::themeJaspRaw() +
|
614 | 619 | ggplot2::theme(axis.ticks.x = ggplot2::element_blank())
|
|
0 commit comments