draw_dots | R Documentation |
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
)
x |
Either a numeric vector or a data frame. |
y |
An optional numeric vector matching in length to |
lb |
An optional numeric vector matching in length to |
ub |
An optional numeric vector matching in length to |
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 |
cex |
The size of the points to draw
(see |
lwd |
The width of the lines
(see |
length |
The width of the caps on the error bars. |
col |
The color of the points
(see |
bg |
The background color of the points
(see |
col.eb |
The color of the error bars. |
aes |
An optional named character vector specifying
column names (if |
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 )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.