spider: Spider plot

View source: R/plot2.R

spiderR Documentation

Spider plot

Description

Draw a spider plot.

Usage

spider(
  x = NULL,
  y,
  group = NULL,
  start = NULL,
  breaks = NULL,
  col = NULL,
  lwd = par("lwd"),
  lty = par("lty"),
  labels = unique(group),
  at.labels = NULL,
  col.labels = col,
  horiz = TRUE,
  panel.first = NULL,
  panel.last = NULL,
  ...
)

Arguments

x, y

numeric vectors of data; note that x is optional and if undefined, y values are plotted at seq_along(y) on the x-axis (separately for each group)

group

a vector defining groups

start

an optional vector of length 1 or 2 giving the starting values for x and y, respectively

breaks

a vector of cut points for y; segments that end in the nth interval of breaks will be colored with col[n]

col, lwd, lty

if breaks is NULL, a vector of colors, line withds, and line types for each group; otherwise, vectors for each break

labels

optional labels for each group, plotted at the last value of y for each group

at.labels, col.labels

vectors of x-coordinates and colors for each group label

horiz

logical; if TRUE (default), the plot is drawn with time on the x-axis; otherwise, time is on the y-axis

panel.first, panel.last

expressions to be evaluated before or after plotting takes place

...

additional arguments passed to plot.default or graphical parameters further passed to par

Examples

## basic usage
spider(y = airquality$Temp[airquality$Day == 1])
with(airquality, spider(Day[Month == 5], Temp[Month == 5]))

## with groups
with(airquality, spider(Day, Temp, group = Month))
with(airquality, spider(Day, Temp - mean(Temp), group = Month, start = 0))
with(airquality, {
  spider(Day, Temp - mean(Temp), group = Month, start = 0,
         labels = month.abb[unique(Month)],
         at.labels = par('usr')[2], col.labels = 1:5)
})

## with breaks
br <- c(0, 70, 80, 90, 120)
cc <- c('black', 'yellow', 'orange', 'red')
spider(
  y = airquality$Temp, breaks = br, col = cc, ylim = c(50, 100),
  xlab = 'Time from start', ylab = 'Temperature',
  bty = 'l', las = 1L, lwd = 2, labels = 'Current',
  panel.first = {
    p <- par('usr')
    rect(p[1], br[-length(br)], p[2], br[-1],
         col = adjustcolor(cc, 0.1), border = NA)
  },
  panel.last = {
    points(airquality$Temp, pch = 18,
           col = ifelse(airquality$Temp > 90, 2, NA))
    points(nrow(airquality), airquality$Temp[nrow(airquality)], pch = 18)
  }
)


raredd/plotr documentation built on Nov. 19, 2023, 4:09 a.m.