#' @param X matrix of covariates (of size n*p)
#' @param Y matrix of responses (of size n*m)
#' @param model the model constructed by valse procedure
-#' @param n sample size
-#' @return several plots
+#' @param comp TRUE to enable pairwise clusters comparison
+#' @param k1 index of the first cluster to be compared
+#' @param k2 index of the second cluster to be compared
#'
-#' @examples TODO
+#' @importFrom ggplot2 ggplot aes ggtitle geom_tile geom_line geom_point scale_fill_gradient2 geom_boxplot theme
+#' @importFrom cowplot background_grid
+#' @importFrom reshape2 melt
#'
#' @export
-#'
-plot_valse <- function(X, Y, model, n, comp = FALSE, k1 = NA, k2 = NA)
+plot_valse <- function(X, Y, model, comp = FALSE, k1 = NA, k2 = NA)
{
- require("gridExtra")
- require("ggplot2")
- require("reshape2")
- require("cowplot")
-
+ n <- nrow(X)
K <- length(model$pi)
## regression matrices
gReg <- list()
for (r in 1:K)
{
Melt <- melt(t((model$phi[, , r])))
- gReg[[r]] <- ggplot(data = Melt, aes(x = Var1, y = Var2, fill = value)) +
+ gReg[[r]] <- ggplot(data = Melt, aes(x = "Var1", y = "Var2", fill = "value")) +
geom_tile() + scale_fill_gradient2(low = "blue", high = "red", mid = "white",
midpoint = 0, space = "Lab") + ggtitle(paste("Regression matrices in cluster", r))
}
## Differences between two clusters
if (comp)
{
- if (is.na(k1) || is.na(k))
+ if (is.na(k1) || is.na(k2))
print("k1 and k2 must be integers, representing the clusters you want to compare")
Melt <- melt(t(model$phi[, , k1] - model$phi[, , k2]))
- gDiff <- ggplot(data = Melt, aes(x = Var1, y = Var2, fill = value))
+ gDiff <- ggplot(data = Melt, aes(x = "Var1", y = "Var2", fill = "value"))
+ geom_tile()
+ scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0,
space = "Lab")
for (r in 1:K)
matCov[, r] <- diag(model$rho[, , r])
MeltCov <- melt(matCov)
- gCov <- ggplot(data = MeltCov, aes(x = Var1, y = Var2, fill = value)) + geom_tile()
+ gCov <- ggplot(data = MeltCov, aes(x = "Var1", y = "Var2", fill = "value")) + geom_tile()
+ scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0,
space = "Lab")
+ ggtitle("Covariance matrices")
for (i in 1:n)
gam2[i, ] <- c(model$proba[i, model$affec[i]], model$affec[i])
- bp <- ggplot(data.frame(gam2), aes(x = X2, y = X1, color = X2, group = X2))
+ bp <- ggplot(data.frame(gam2), aes(x = "X2", y = "X1", color = "X2", group = "X2"))
+ geom_boxplot()
+ theme(legend.position = "none")
+ background_grid(major = "xy", minor = "none")
}
data <- data.frame(mean = as.vector(meanPerClass),
cluster = as.character(rep(1:K, each = dim(XY)[2])), time = rep(1:dim(XY)[2], K))
- g <- ggplot(data, aes(x = time, y = mean, group = cluster, color = cluster))
- print(g + geom_line(aes(linetype = cluster, color = cluster))
- + geom_point(aes(color = cluster)) + ggtitle("Mean per cluster"))
+ g <- ggplot(data, aes(x = "time", y = "mean", group = "cluster", color = "cluster"))
+ print(g + geom_line(aes(linetype = "cluster", color = "cluster"))
+ + geom_point(aes(color = "cluster")) + ggtitle("Mean per cluster"))
}