draw_dots.Rd
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
)
Either a numeric vector or a data frame.
An optional numeric vector matching in length to x
.
An optional numeric vector matching in length to x
,
specifying the lower bounds for error bars.
An optional numeric vector matching in length to x
,
specifying the upper bounds for error bars.
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.
The type of point to draw
(see par
).
The size of the points to draw
(see par
).
The width of the lines
(see par
).
The width of the caps on the error bars.
The color of the points
(see par
).
The background color of the points
(see par
).
The color of the error bars.
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
.
Adds points and error bars to an existing plot.
# 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 )