Question

I am trying to plot ladder plot as described on this page: http://www.talkstats.com/showthread.php/6252-Ladder-plot

Can this code be modified to show mean and standard error bars also on either side of plot? Alternatively, box plots for both columns could be shown on the same plot. Some code for standard error bars is available on this page: https://stats.stackexchange.com/questions/60767/how-to-display-error-bars-for-cross-over-paired-experiments

Thanks for your help.

Edited: Sample paired data is given below:

paired_df = structure(list(X0 = c(9, 13, 13, 13, 35, 36, 37, 38, 39, 40, 
+ 40, 42, 43, 44), X0.1 = c(10, 40, 45, 46, 36, 37, 38, 40, 46, 
+ 45, 46, 43, 44, 46)), .Names = c("A", "B"), row.names = c(NA, 
+ 14L), class = "data.frame")
    A  B
1   9 10
2  13 40
3  13 45
4  13 46
5  35 36
6  36 37
7  37 38
8  38 40
9  39 46
10 40 45
11 40 46
12 42 43
13 43 44
14 44 46
Was it helpful?

Solution 2

You should understand (although many people do not) that boxplots show neither means nor standard deviations and they don't display the interquartile range except by accident. You could use the same strategy to "annotate a boxplot". (Using the data construction of the prior question.)

x<-data.frame(A=c(1:10), B=c(1:10)+rnorm(10))
xx<-stack(x) # restructures data for stripchart function

with( xx, boxplot(values~ind))
apply(x,1,lines, col="blue")
apply(x,1,points, col="red")

enter image description here

This could probably be improved for more general use by using smaller points and having the colors be transparent, if there were large numbers of cases.

OTHER TIPS

Here are a two leads for you:

  1. To create a ladder plot, the easiest way is to use the ladderplot function from the plotrix package. Code example:
# install.packages('plotrix')  ## this is to install the plotrix package
require('plotrix')
ladderplot(my.2.columns.matrix)

. 2. To overlay error bars, the easiest way is to use the errbar function from the Hmisc package. Code example:

# install.packages('Hmisc')  ## this is to install the Hmisc package
require('Hmisc')
errbar(c(1,2),c(mean1, mean2),c(mean1-sem1,mean2-sem2),c(mean1+sem1,mean2+sem2),add=TRUE)

Try to adjust these pieces of code to make them work for you, and comment if you are stuck somewhere.

edited to add a full example:

See a full code example, and the resulting picture:

require('plotrix')
require('Hmisc')

vals = cbind(rnorm(5,mean=3,sd=1), rnorm(5,mean=5,sd=1))

ladderplot(vals)

means = colMeans(vals)
sems = apply(vals, 2, function(x) sd(x)/sqrt(length(x)))

errbar(c(1,2),c(means[1], means[2]),c(means[1]-sems[1],means[2]-sems[2]),c(means[1]+sems[1],means[2]+sems[2]),
       add=TRUE,
       errbar.col='red',col='red')

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top