Learn R Programming

DataVisualizations (version 1.1.12)

Classplot: Classplot

Description

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).

Usage

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)

Arguments

X

[1:n] numeric vector or time

Y

[1:n] numeric vector of feature

Cls

[1:n] numeric vector of k classes, if not set per default every point is in first class

Names

[1:n] character vector of k classes, if not set perdefault Cls is used, if set, names the legend and the points

na.rm

Function may not work with non finite values. If these cases should be automatically removed, set parameter TRUE

xlab

Optional, string for xlabel

ylab

Optional, string for ylabel

main

Optional, string for title of plot

Colors

Optional, string defining the k colors, one per class

Size

Optional, size of points

LineColor

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

LineWidth

Optional, number defining the width of the curve (plotly only)

LineType

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

Showgrid

Optional, boolean (plotly only)

Plotter

Optional, either "ggplot" or "plotly", other string results in simple native plot

SaveIt

Optional, boolean, if true saves plot as html (plotly) or png (ggplot2)

Value

plotly object or ggplot2 objected depending on Plotter

Details

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.

See Also

DualaxisClassplot

Examples

Run this code
# 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