plotScatter: Scatter plot

View source: R/plotScatter.R

plotScatterR Documentation

Scatter plot

Description

Produces a plot describing the relationship between two columns of the outcomes matrix Y. It allows to chose colors and markers for the levels of the design factors. Ellipses, polygones or segments can be added to group sets of points on the graph.

Usage

plotScatter(
  Y,
  xy,
  design = NULL,
  color = NULL,
  shape = NULL,
  points_labs = NULL,
  title = "Scatter plot",
  xlab = NULL,
  ylab = NULL,
  size = 2,
  size_lab = 3,
  drawShapes = c("none", "ellipse", "polygon", "segment"),
  typeEl = c("norm", "t", "euclid"),
  levelEl = 0.9,
  alphaPoly = 0.4,
  theme = theme_bw()
)

Arguments

Y

A nxm matrix with n observations and m variables.

xy

x- and y-axis values: a vector of length 2 with either the column name(s) of the Y matrix to plot (character) or the index position(s).

design

A nxk "free encoded" experimental design data frame.

color

If not NULL, a character string giving the column name of design to be used as color.

shape

If not NULL, a character string giving the column name of design to be used as shape.

points_labs

If not NULL, a character vector with point labels.

title

Plot title.

xlab

If not NULL, label for the x-axis.

ylab

If not NULL, label for the y-axis.

size

The points size.

size_lab

The size of points labels.

drawShapes

Multiple shapes can be drawn based on the color: "none" for non shape (default), "ellipse" (ellipses with ggplot2::stat_ellipse), "polygon" (polygons with ggplot2::geom_polygon) or "segment" (segment from the centroids with ggplot2::geom_segment).

typeEl

The type of ellipse, either norm (multivariate normal distribution), t (multivariate t-distribution) or euclid (draws a circle with the radius equal to level, representing the euclidean distance from the center).

levelEl

The confidence level at which to draw an ellipse.

alphaPoly

The degree of transparency for polygons.

theme

ggplot theme, see ?ggtheme for more info.

Value

A scatter plot (ggplot).

Examples


data("UCH")

# Without design
plotScatter(Y = UCH$outcomes, xy = c(453, 369))

# With color and shape
plotScatter(Y = UCH$outcomes, design = UCH$design,
            xy = c(453, 369), color = "Hippurate",
            shape = "Citrate")

# With color and drawShapes
plotScatter(Y = UCH$outcomes, design = UCH$design,
            xy = c(453, 369), color = "Hippurate",
            drawShapes = "ellipse")

plotScatter(Y = UCH$outcomes, design = UCH$design,
            xy = c(453, 369), color = "Hippurate",
            drawShapes = "polygon")

plotScatter(Y = UCH$outcomes, design = UCH$design,
            xy = c(453, 369), color = "Hippurate",
            drawShapes = "segment")

# Customize shapes
library(ggplot2)
plotScatter(Y = UCH$outcomes, design = UCH$design,
            xy = c(453, 369), shape = "Hippurate", size = 3) +
  scale_discrete_identity(aesthetics = 'shape',
                          guide = 'legend')

plotScatter(Y = UCH$outcomes, design = UCH$design,
            xy = c(453, 369), shape = "Hippurate") +
  scale_shape_discrete(solid=FALSE)

plotScatter(Y = UCH$outcomes, design = UCH$design,
            xy = c(453, 369), shape = "Hippurate") +
  scale_shape_manual(values = c(15,16,17))

# With labels
plotScatter(Y = UCH$outcomes, design = UCH$design,
            xy = c(453, 369), points_labs = rownames(UCH$design))


bgovaerts/LMWiRe documentation built on Sept. 17, 2022, 12:32 a.m.