Skip to content
Snippets Groups Projects
Commit b6c8aa3d authored by Nathalie Vialaneix's avatar Nathalie Vialaneix
Browse files

add time in quality plots (fixed #8)

parent 9f47248a
No related branches found
Tags v0.2.1
No related merge requests found
......@@ -319,17 +319,42 @@ plot_selection <- function(x, sel.type, threshold) {
plot_quality <- function(x, quality.crit) {
valid_criteria <- "mse"
if ("computational.times" %in% names(x)) {
valid_criteria <- c(valid_criteria, "time")
}
if ("quality" %in% names(x)) {
valid_criteria <- c("mse", "Precision", "Recall", "ARI", "NMI")
} else valid_criteria <- "mse"
valid_criteria <- c(valid_criteria, "Precision", "Recall", "ARI", "NMI")
}
crit_ok <- all(sapply(quality.crit, function(cc) cc %in% valid_criteria))
if (!crit_ok || length(quality.crit) > 2) {
stop(paste0("'quality.crit' must be a vector with length at most 2 in ",
paste(valid_criteria, collapse = ", "), "."))
paste(valid_criteria, collapse = ", "), "."),
call. = FALSE)
}
if (length(quality.crit) == 2 && "time" %in% quality.crit) {
stop("'time' is a valid quality criterion to plot only taken alone.",
call. = FALSE)
}
if ("time" %in% quality.crit) {
df <- data.frame("criterion" = c(unname(x$"computational.times")),
"step" = names(x$"computational.times"))
df$step <- factor(df$step, levels = names(x$"computational.times"),
ordered = TRUE)
p <- ggplot(df, aes(fill = .data$step, y = .data$criterion, x = 1)) +
geom_bar(stat = "identity") + theme_bw() + xlim(0, 2) +
ylab("computational time (s)") +
theme(axis.title.x = element_blank(), axis.ticks.x = element_blank(),
axis.text.x = element_blank()) +
scale_fill_brewer(type = "qual", palette = 7)
return(p)
}
if (length(quality.crit) == 1) {
# build data frame
if (quality.crit == "mse") {
df <- data.frame("criterion" = x$mse$mse, "at" = x$mse$clust)
ylimits <- c(0, max(df$criterion))
......@@ -340,11 +365,14 @@ plot_quality <- function(x, quality.crit) {
ylimits <- c(-1, 1)
} else ylimits <- c(0, 1)
}
# make plot
p <- ggplot(df, aes(x = .data$at, y = .data$criterion)) +
geom_jitter(width=0.2, height = 0) + theme_bw() +
xlab("number of intervals") + ylab(quality.crit) + ylim(ylimits) +
scale_x_continuous(breaks = unique(df$at),
limits = c(min(df$at) - 0.5, max(df$at + 0.5)))
} else {
if ("mse" %in% quality.crit) {
quality.crit <- setdiff(quality.crit, "mse")
......
......@@ -27,7 +27,9 @@
#' represent the importance. Default to \code{"boxplot"}
#' @param quality.crit character vector (length 1 or 2) indicating one or two
#' quality criteria to display. The values have to be taken in \{\code{"mse"},
#' \code{"Precision"}, \code{"Recall"}, \code{"ARI"}, \code{"NMI"}\}
#' \code{"time"}, \code{"Precision"}, \code{"Recall"}, \code{"ARI"},
#' \code{"NMI"}\}. If \code{"time"} is chosen, it can not be associated with any
#' other criterion
#' @param ... not used
#' @param at numeric vector. Set of the number of intervals to extract for
#' @param ground_truth numeric vector of ground truth. Target variables
......
......@@ -51,7 +51,9 @@ represent the importance. Default to \code{"boxplot"}}
\item{quality.crit}{character vector (length 1 or 2) indicating one or two
quality criteria to display. The values have to be taken in \{\code{"mse"},
\code{"Precision"}, \code{"Recall"}, \code{"ARI"}, \code{"NMI"}\}}
\code{"time"}, \code{"Precision"}, \code{"Recall"}, \code{"ARI"},
\code{"NMI"}\}. If \code{"time"} is chosen, it can not be associated with any
other criterion}
\item{at}{numeric vector. Set of the number of intervals to extract for}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment