Learn R Programming

psych (version 1.0-17)

# error.crosses: Plot x and y error bars

## Description

Given two vectors of data, plot the means and show standard errors in both X and Y directions.

## Usage

`error.crosses(x, y, labels = NULL, pos = NULL, arrow.len = 0.2, ...)`

## Arguments

x
A vector of summary statistics (from Describe)
y
A second vector of summary statistics (also from Describe)
labels
name the pair
pos
Labels are located where with respect to the mean?
arrow.len
Arrow length
...
Other parameters for plot

## Details

For an example of two way error bars describing the effects of mood manipulations upon positive and negative affect, see http://personality-project.org/revelle/publications/happy-sad-appendix/FIG.A-6.pdf)

## Examples

Run this code
``````#desc <- describe(attitude)
#x <- desc[1,]
#y <- desc[2,]
#plot(x\$mean,y\$mean)   #in graphics window
#error.crosses(x,y)    #in graphics window

## The function is currently defined as

function (x,y,labels=NULL,pos=NULL,arrow.len=.2,...)  # x  and y are data frame with
{z <- dim(x)[1]
if (length(pos)==0) {locate <- rep(1,z)} else {locate <- pos}
if (length(labels)==0) lab <- rep("",z) else lab <-labels
for (i in 1:z)
{xcen <- x\$mean[i]
ycen <- y\$mean[i]
xse  <- x\$se[i]
yse <-  y\$se[i]
arrows(xcen-xse,ycen,xcen+xse,ycen,length=arrow.len, angle = 90,
code=3,col = par("fg"), lty = NULL, lwd = par("lwd"), xpd = NULL)
arrows(xcen,ycen-yse,xcen,ycen+yse,length=arrow.len, angle = 90,
code=3,col = par("fg"), lty = NULL, lwd = par("lwd"), xpd = NULL)
text(xcen,ycen,labels=lab[i],pos=pos[i],cex=1,offset=arrow.len+1)
#puts in labels for all points
}
}``````

Run the code above in your browser using DataLab