mplnVisualizeLine: Visualize Clustered Results Via Line Plots

View source: R/mplnVisualize.R

mplnVisualizeLineR Documentation

Visualize Clustered Results Via Line Plots

Description

A function to visualize clustering results via line plots. Each cluster will have its own plot. Data is log-transformed prior to visualizing. Values for each sample are connected by dashed lines to illustrate the trends (log counts). The yellow line shows the mean value (log counts) for each cluster.

Usage

mplnVisualizeLine(
  dataset,
  clusterMembershipVector = NA,
  fileName = paste0("Plot_", date()),
  LinePlotColours = "black",
  printPlot = TRUE,
  format = "pdf"
)

Arguments

dataset

A dataset of class matrix and type integer such that rows correspond to observations and columns correspond to variables.

clusterMembershipVector

A numeric vector of length nrow(dataset) containing the cluster membership of each observation. If not provided, all observations will be treated as belonging to one cluster. Default is NA.

fileName

Unique character string indicating the name for the plot being generated. Default is Plot_date, where date is obtained from date().

LinePlotColours

Character string indicating if the line plots should be multicoloured or monotone, in black. Options are 'multicolour' or 'black'. Default is 'black'.

printPlot

Logical indicating if plot(s) should be saved in local directory. Default TRUE. Options TRUE or FALSE.

format

Character string indicating the format of the image to be produced. Default 'pdf'. Options 'pdf' or 'png'.

Value

Plotting function provides the possibility for line plots.

Author(s)

Anjali Silva, anjali@alumni.uoguelph.ca

Examples

# Example 1
# Setting parameters
trueMu1 <- c(6.5, 6, 6, 6, 6, 6)
trueMu2 <- c(2, 2.5, 2, 2, 2, 2)

trueSigma1 <- diag(6) * 2
trueSigma2 <- diag(6)

# Generate simulated data
simulatedCounts <- MPLNClust::mplnDataGenerator(nObservations = 100,
                                      dimensionality = 6,
                                      mixingProportions = c(0.79, 0.21),
                                      mu = rbind(trueMu1, trueMu2),
                                      sigma = rbind(trueSigma1, trueSigma2),
                                      produceImage = "No")

 # Clustering data
 MPLNClustResults <- MPLNClust::mplnVariational(
                              dataset = as.matrix(simulatedCounts$dataset),
                              membership = "none",
                              gmin = 1,
                              gmax = 2,
                              initMethod = "kmeans",
                              nInitIterations = 1,
                              normalize = "Yes")

 # Visualize data using line plot
 MPLNLineBlack <- MPLNClust::mplnVisualizeLine(dataset = simulatedCounts$dataset,
                                         clusterMembershipVector =
                                         MPLNClustResults$allResults$`G=2`$clusterlabels,
                                         fileName = 'TwoClusterModel',
                                         printPlot = FALSE,
                                         format = 'png')

 # Visualize data using line plot with multicolours
 # Use navigation buttons to see previous plots
 MPLNLineColor <- MPLNClust::mplnVisualizeLine(dataset = simulatedCounts$dataset,
                                         clusterMembershipVector =
                                         MPLNClustResults$allResults$`G=2`$clusterlabels,
                                         fileName = 'TwoClusterModel',
                                         LinePlotColours = "multicolour",
                                         printPlot = FALSE,
                                         format = 'png')

 # Example 2
 # Carry out K-means clustering for same dataset as above
 # Use navigation buttons to see previous plots
 set.seed(1234)
 KmeansLineColor <- MPLNClust::mplnVisualizeLine(dataset = simulatedCounts$dataset,
                                         clusterMembershipVector =
                                         kmeans(simulatedCounts$dataset, 3)$cluster,
                                         fileName = 'ThreeClusterKmeansModel',
                                         LinePlotColours = "multicolour",
                                         printPlot = FALSE,
                                         format = 'png')


anjalisilva/MPLNClust documentation built on Jan. 28, 2024, 11:02 a.m.