Learn R Programming

itsadug (version 2.0)

add_bars: Adding bars to an existing plot.

Description

Adding bars to an existing plot.

Usage

add_bars(x, y, y0 = NULL, width = 1, horiz = FALSE, ...)

Arguments

x
Numeric vector with x-positions of bars.
y
Numeric vector with height of the bars.
y0
Optional numeric value or vector with the onset(s) of the bars. When y0 is not specified, the lowest value of the y-axis is used.
width
Numeric value, determining the width of the bars in units of the x-axis.
horiz
Logical value: whether or not to plot horizontal bars. Defaults to FALSE.
...
Other arguments for plotting, see par.

See Also

Other Functions for plotting: addInterval, alphaPalette, alpha, check_normaldist, color_contour, dotplot_error, drawArrows, emptyPlot, errorBars, fadeRug, fill_area, getCoords, getFigCoords, getProps, gradientLegend, marginDensityPlot, plot_error, plot_image, plotsurface, rug_model

Examples

Run this code
data(simdat)

# averages per condition:
subj <- with(simdat, aggregate(Y, 
    list(Group=Group, Condition=Condition, Subject=Subject), mean))
avg  <- with(subj, tapply(x, list(Group, Condition), mean))
ses  <- with(subj, tapply(x, list(Group, Condition), se))

# barplot of Adults:
b <- barplot(avg['Adults',], beside=TRUE)
# overlay addbars:
add_bars(b, avg['Children',], density=25)

# or some variants:
b <- barplot(avg['Adults',], beside=TRUE)
add_bars(b+.1, avg['Children',], col=alpha('red'))

# also the option to make your own type of plot:
emptyPlot(c(-10,10), c(-2,5), v0=0, ylab="Condition")
add_bars(-1*avg["Children",], -1:4, y0=0, col=alpha("blue"), 
    border="blue", horiz=TRUE)
add_bars(avg["Adults",], -1:4, y0=0, col=alpha("black"), 
    border=1, horiz=TRUE, xpd=TRUE)
mtext(c("Children", "Adults"), side=3, at=c(-5,5), line=1, cex=1.25, font=2)

Run the code above in your browser using DataLab