|
476 | 476 | table$setData(clusterMeans)
|
477 | 477 | }
|
478 | 478 |
|
479 |
| -.mlClusteringPlotDensities <- function(dataset, options, jaspResults, ready, position) { |
| 479 | +.mlClusteringPlotDensities <- function(dataset, options, jaspResults, ready, position, type) { |
480 | 480 | if (!is.null(jaspResults[["clusterDensities"]]) || !options[["clusterDensityPlot"]]) {
|
481 | 481 | return()
|
482 | 482 | }
|
|
488 | 488 | return()
|
489 | 489 | }
|
490 | 490 | clusterResult <- jaspResults[["clusterResult"]]$object
|
| 491 | + predictions <- clusterResult[["pred.values"]] |
| 492 | + ncolors <- clusterResult[["clusters"]] |
| 493 | + if (type == "densitybased") { |
| 494 | + ncolors <- ncolors + 1 |
| 495 | + predictions[predictions == 0] <- gettext("Noisepoint") |
| 496 | + } |
| 497 | + clusters <- as.factor(predictions) |
491 | 498 | if (!options[["clusterDensityPlotSingleFigure"]]) {
|
492 | 499 | for (variable in unlist(options[["predictors"]])) {
|
493 |
| - clusters <- as.factor(clusterResult[["pred.values"]]) |
494 | 500 | xBreaks <- jaspGraphs::getPrettyAxisBreaks(dataset[[variable]], min.n = 4)
|
495 | 501 | plotData <- data.frame(
|
496 | 502 | cluster = clusters,
|
|
500 | 506 | ggplot2::geom_density(mapping = ggplot2::aes(fill = cluster), color = "black", alpha = 0.6) +
|
501 | 507 | ggplot2::scale_x_continuous(name = variable, breaks = xBreaks, limits = range(xBreaks)) +
|
502 | 508 | ggplot2::scale_y_continuous(name = gettext("Density")) +
|
503 |
| - ggplot2::scale_fill_manual(name = gettext("Cluster"), values = .mlColorScheme(length(levels(clusters)))) + |
| 509 | + ggplot2::scale_fill_manual(name = gettext("Cluster"), values = .mlColorScheme(ncolors)) + |
504 | 510 | jaspGraphs::geom_rangeframe() +
|
505 | 511 | jaspGraphs::themeJaspRaw(legend.position = "right") +
|
506 | 512 | ggplot2::theme(axis.ticks.y = ggplot2::element_blank(), axis.text.y = ggplot2::element_blank())
|
|
509 | 515 | }
|
510 | 516 | } else {
|
511 | 517 | dataList <- c(dataset[, options[["predictors"]]])
|
512 |
| - plotData <- data.frame(value = unlist(dataList), variable = rep(options[["predictors"]], lengths(dataList)), cluster = rep(clusterResult[["pred.values"]], length(options[["predictors"]]))) |
| 518 | + plotData <- data.frame(value = unlist(dataList), variable = rep(options[["predictors"]], lengths(dataList)), cluster = rep(predictions, length(options[["predictors"]]))) |
513 | 519 | xBreaks <- jaspGraphs::getPrettyAxisBreaks(plotData[["value"]])
|
514 | 520 | p <- ggplot2::ggplot(data = plotData, mapping = ggplot2::aes(x = value, y = factor(variable), height = ..density.., fill = factor(cluster))) +
|
515 | 521 | ggridges::geom_density_ridges(stat = "density", alpha = .6) +
|
516 |
| - ggplot2::scale_fill_manual(name = gettext("Cluster"), values = .mlColorScheme(length(unique(clusterResult[["pred.values"]])))) + |
| 522 | + ggplot2::scale_fill_manual(name = gettext("Cluster"), values = .mlColorScheme(ncolors)) + |
517 | 523 | ggplot2::scale_x_continuous(name = gettext("Value"), breaks = xBreaks, limits = range(xBreaks)) +
|
518 | 524 | ggplot2::scale_y_discrete(name = gettext("Feature")) +
|
519 | 525 | jaspGraphs::geom_rangeframe(sides = "b") +
|
|
0 commit comments