Function to add points and error bars to an existing plot.

draw_dots(
  x,
  y = NULL,
  lb = NULL,
  ub = NULL,
  columns = NULL,
  pch = 19,
  cex = 1.25,
  lwd = 2,
  length = 0.05,
  col = "black",
  bg = "white",
  col.eb = "black",
  aes = NULL
)

Arguments

x

Either a numeric vector or a data frame.

y

An optional numeric vector matching in length to x.

lb

An optional numeric vector matching in length to x, specifying the lower bounds for error bars.

ub

An optional numeric vector matching in length to x, specifying the upper bounds for error bars.

columns

A character vector of either 2 or 4 elements, the column names for the x and y-axis values and (optionally) the column names for the lower and upper bounds of the error bars.

pch

The type of point to draw (see par).

cex

The size of the points to draw (see par).

lwd

The width of the lines (see par).

length

The width of the caps on the error bars.

col

The color of the points (see par).

bg

The background color of the points (see par).

col.eb

The color of the error bars.

aes

An optional named character vector specifying column names (if x is a data frame) with values for pch, cex, lwd, col, bg, and col.eb.

Value

Adds points and error bars to an existing plot.

Examples

# Add three points
plot_blank()
draw_dots( c( 0, .5, 1 ), c( 0, .5, 1 ) )

# Pass points in via data frame
draw_dots(
  data.frame( X = c( .1, .2, .3 ), Y = c( .8, .8, .8 ) ),
  col = 'blue'
)


# Compute mean, SE, and 95% CI limits for data set
dtf <- aggregate(
  mtcars$mpg, list( mtcars$cyl ), function(x) c( mean(x), sem(x) )
)
dtf$X <- 1:3
dtf$M <- dtf$x[,1];
dtf$LB <- dtf$x[,1] - dtf$x[,2] * 1.96
dtf$UB <- dtf$x[,1] + dtf$x[,2] * 1.96

# Create blank plot
xl <- c( .5, 3.5 ); yl <- c( 10, 30 )
plot_blank( xl, yl )
draw_hv( h = yl, l = xl )
draw_hv( v = xl, l = yl )

draw_dots(
  dtf, columns = c( 'X', 'M', 'LB', 'UB' ),
  col = palettes( index = 1:3 )
)

# Add axes and labels
draw_axes( 1:3, dtf$Group.1 )
mtext( 'Cylinders', side = 1, line = 2, cex = 1.25 )
draw_axes( c( 10, 20, 30 ), side = 2 )
mtext( 'MPG', side = 2, line = 2, cex = 1.25 )