Classplot {DataVisualizations}R Documentation

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.

Usage

Classplot(X, Y, Cls, Plotter,Names = NULL, na.rm = FALSE, 

xlab = "X", ylab = "Y", main = "Class Plot", Colors = NULL,

Size = 8,PointBorderCol="black",

LineColor = NULL, LineWidth = 1, LineType  = NULL, 

Showgrid  = TRUE, pch,  AnnotateIt = FALSE, SaveIt = FALSE, 

Nudge_x_Names = 0, Nudge_y_Names = 0, Legend = "", ...)

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 per default 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, [1;k] string defining the k colors, one per class

AnnotateIt

Optional, in case of Plotter==ggplot and given Names annotates each point if TRUE

Size

Optional, size of points, beware: default is appropriate for "plotly", or "native" but should smaller for "ggplot"

PointBorderCol

Optional, string, color of the dot outline for "plotly" for "ggplot". If FALSE and Plotter="ggplot" or Plotter="plotly", no borders for points which is useful if many points overlap.

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" (default if Names given), "plotly" (default if no Names given), or "native"

pch

[1:n] numeric vector of length n of the cases of Cls for the k classes. It defines the symbols to use, for native Plotter or ggplot, usally k can be in a range from zero to 25

SaveIt

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

Nudge_x_Names

Optional, numerical scalar, for Plotter "ggplot" only, if Names are set, moves them consistently respective to x-axis within units of x-axis

Nudge_y_Names

Optional, numerical scalar, for Plotter "ggplot" only, if Names are set, moves them consistently respective to y-axis within units of y-axis

Legend

Optional, if argument is not missing, character string defining the title of the legend which automatically enables the legend

...

Further arguments for ggplot2::ggplot,or plotly::plot_ly, or plot (except "pch"" and "type") 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.

For example, the function is usefull to see if temporal clustering has time dependent variations and for Hidden Markov Models (see Mthrun/RHmm on GitHub).

Value

plotly object or ggplot2 objected depending on Plotter

Author(s)

Michael Thrun

See Also

DualaxisClassplot

Examples

data(Lsun3D)
Classplot(Lsun3D$Data[,1],Lsun3D$Data[,2],Lsun3D$Cls)

#ggplot 2 with different symbols
  Classplot(
    Lsun3D$Data[, 1],
    Lsun3D$Data[, 2],
    Lsun3D$Cls,
    Plotter = "ggplot2",
    Size = 3,
    pch = Lsun3D$Cls + 5
  )

#plotly with line
data(Lsun3D)
Classplot(Lsun3D$Data[,1],Lsun3D$Data[,2],Lsun3D$Cls,
LineType="-",LineColor = "green")

#ggplot2 with annotations
data(Lsun3D)
ind=sample(1:nrow(Lsun3D$Data),20)
Classplot(Lsun3D$Data[ind,1],Lsun3D$Data[ind,2],Lsun3D$Cls[ind],
Names = rownames(Lsun3D$Data)[ind],Size =1,
Plotter = "ggplot2",AnnotateIt = TRUE)



#ggplot2 with labels and legend per class
data(Lsun3D)
Classplot(Lsun3D$Data[,1],Lsun3D$Data[,2],Lsun3D$Cls,
Names = paste0("C",Lsun3D$Cls),Size =2,Legend ="Classes")


[Package DataVisualizations version 1.3.2 Index]