scatterplot {BasketballAnalyzeR}R Documentation

Draws a scatter plot or a matrix of scatter plots

Description

Draws a scatter plot or a matrix of scatter plots

Usage

scatterplot(
  data,
  data.var,
  z.var = NULL,
  palette = NULL,
  labels = NULL,
  repel_labels = FALSE,
  text_label = TRUE,
  subset = NULL,
  col.subset = "gray50",
  zoom = NULL,
  title = NULL,
  legend = TRUE,
  upper = list(continuous = "cor", combo = "box_no_facet", discrete = "facetbar", na =
    "na"),
  lower = list(continuous = "points", combo = "facethist", discrete = "facetbar", na =
    "na"),
  diag = list(continuous = "densityDiag", discrete = "barDiag", na = "naDiag")
)

Arguments

data

an object of class data.frame.

data.var

character or numeric vector, name or column number of variables (in data object) used on the axes of scatter plot(s).

z.var

character or number, name or column number of variable (in data object) used to assign colors to points (see Details).

palette

color palette (active when plotting a single scatter plot; see Value).

labels

character vector, labels for points (active when plotting a single scatter plot, see Value).

repel_labels

logical; if TRUE, draws text labels of not highlighted points using repelling (active when plotting a single scatter plot; see Value).

text_label

logical; if TRUE, draws a rectangle behind the labels of highlighted points (active when plotting a single scatter plot; see Value).

subset

logical or numeric vector, to select a subset of points to be highlighted (active when plotting a single scatter plot; see Value).

col.subset

character, color for the labels and rectangles of highlighted points (active when plotting a single scatter plot; see Value).

zoom

numeric vector with 4 elements; c(xmin,xmax,ymin,ymax) for the x- and y-axis limits of the plot (active when plotting a single scatter plot; see Value).

title

character, plot title.

legend

logical, if legend=FALSE legend is removed (active when plotting a single scatter plot with z.var not NULL; see Value).

upper

list, may contain the variables continuous, combo, discrete, and na (active when plotting a matrix of scatter plot; see Value and upper in ggpairs)

lower

list, may contain the variables continuous, combo, discrete, and na (active when plotting a matrix of scatter plot; see Value and lower in ggpairs)

diag

list, may contain the variables continuous, discrete, and na (active when plotting a matrix of scatter plot; see Value and diag in ggpairs)

Details

If length(data.var)=2, the variable specified in z.var can be numeric or factor; if length(data.var)>2, the variable specified in z.var must be a factor.

Value

A ggplot2 object with a single scatter plot if length(data.var)=2 or a matrix of scatter plots if length(data.var)>2.

Author(s)

Marco Sandri, Paola Zuccolotto, Marica Manisera (basketball.analyzer.help@gmail.com)

References

P. Zuccolotto and M. Manisera (2020) Basketball Data Science: With Applications in R. CRC Press.

See Also

ggpairs

Examples

# Single scatter plot
Pbox.sel <- subset(Pbox, MIN>= 500)
X <- data.frame(AST=Pbox.sel$AST/Pbox.sel$MIN,TOV=Pbox.sel$TOV/Pbox.sel$MIN)
X$PTSpm <- Pbox.sel$PTS/Pbox.sel$MIN
mypal <- colorRampPalette(c("blue","yellow","red"))
scatterplot(X, data.var=c("AST","TOV"), z.var="PTSpm", labels=1:nrow(X), palette=mypal)
# Matrix of scatter plots
data <- Pbox[1:50, c("PTS","P3M","P2M","OREB","Team")]
scatterplot(data, data.var=1:4, z.var="Team")

[Package BasketballAnalyzeR version 0.5.0 Index]