scatterplot: Draws a scatter plot or a matrix of scatter plots

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/scatterplot.R

Description

Draws a scatter plot or a matrix of scatter plots

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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

1
2
3
4
5
6
7
8
9
# 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")

Example output

Loading required package: ggplot2
Registered S3 method overwritten by 'GGally':
  method from   
  +.gg   ggplot2

If you want to reproduce the figures contained in the book of
Zuccolotto and Manisera (2020) and
if the version of your R machine is >= 3.6.0, you need to type
RNGkind(sample.kind = "Rounding")
at the beginning of your working session
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

BasketballAnalyzeR documentation built on July 2, 2020, 2:14 a.m.