Allows to plot one time series or feauture with a classification as a labeled scatter plot with a line. The colors are the labels defined by the classification. Usefull to see if temporal clustering has time dependent variations and for Hidden Markov Models (see Mthrun/RHmm on GitHub).
Classplot(X, Y, Cls,Names=NULL,na.rm=FALSE, xlab = "X", ylab = "Y",
main = "Class Plot", Colors,Size=8,
LineColor = NULL, LineWidth = 1, LineType = NULL,
Showgrid = TRUE, Plotter, SaveIt = FALSE)
[1:n] numeric vector or time
[1:n] numeric vector of feature
[1:n] numeric vector of k classes, if not set per default every point is in first class
[1:n] character vector of k classes, if not set perdefault Cls is used, if set, names the legend and the points
Function may not work with non finite values. If these cases should be automatically removed, set parameter TRUE
Optional, string for xlabel
Optional, string for ylabel
Optional, string for title of plot
Optional, string defining the k colors, one per class
Optional, size of points
Optional, name of color, in plotly then all points are connected by a curve,
in ggplot2 all points of one class ae connected by a curve of the color the class
Optional, number defining the width of the curve (plotly only)
Optional, string defining the type of the curve in plotly only, "dot
", "dash
", "-
"
for ggplot2: just set =1 here and then the curve is plotted
Optional, boolean (plotly only)
Optional, either "ggplot
" or "plotly
", other string results in simple native plot
Optional, boolean, if true saves plot as html (plotly) or png (ggplot2)
plotly object or ggplot2 objected depending on Plotter
Default is "plotly
" if Names
are NULL
. However, ggplot2 is preferable in case that Names
parameter is used because overlapping text labels are avoided. In that case the default is "ggplot
". Note that ggplot2 options are currently slightly restricted.
# NOT RUN {
data(Lsun3D)
Classplot(Lsun3D$Data[,1],Lsun3D$Data[,2],Lsun3D$Cls)
#plotly with line
data(Lsun3D)
Classplot(Lsun3D$Data[,1],Lsun3D$Data[,2],Lsun3D$Cls,
LineType="-",LineColor = "green")
# }
# NOT RUN {
#ggplot2 with line and labels
data(Lsun3D)
Classplot(Lsun3D$Data[,1],Lsun3D$Data[,2],Lsun3D$Cls,
Names = rownames(Lsun3D$Data),Size =2,LineType = 1)
# }
Run the code above in your browser using DataLab