Created
February 25, 2017 23:21
-
-
Save tsbaguley/8dcbd11ca36ec6012adc506ddfb6e234 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plot.bsci <- function(data.frame, group.var=1, dv.var=2, difference=TRUE, pooled.error=FALSE, conf.level=0.95, xlab=NULL, ylab=NULL, level.labels=NULL, main=NULL, pch=21, y.lim=c(min.y, max.y), line.width=c(1.5, 0), grid=TRUE, flip=FALSE) { | |
data <- subset(data.frame, select=c(group.var, dv.var)) | |
if(missing(level.labels)) level.labels <- levels(data[[1]]) | |
if (is.factor(data[[1]])==FALSE) data[[1]] <- factor(data[[1]]) | |
if (is.factor(data[[1]])==TRUE) data[[1]] <- factor(data[[1]]) | |
dv <- data[[2]] | |
J <- nlevels(data[[1]]) | |
ci.mat <- bsci(data.frame=data.frame, group.var=group.var, dv.var=dv.var, difference=difference, pooled.error=pooled.error, conf.level=conf.level) | |
moe.y <- max(ci.mat) - min(ci.mat) | |
min.y <- min(ci.mat) - moe.y/3 | |
max.y <- max(ci.mat) + moe.y/3 | |
if (missing(xlab)) | |
xlab <- "Groups" | |
if (missing(ylab)) ylab <- "Confidence interval for mean" | |
if(flip==FALSE){ | |
plot(0, 0, ylim = y.lim, xaxt = "n", xlim = c(0.7, J + 0.3), xlab = xlab, | |
ylab = ylab, main = main) | |
grid() | |
points(ci.mat[,2], pch = pch, bg = "black") | |
index <- 1:J | |
segments(index, ci.mat[, 1], index, ci.mat[, 3], lwd = line.width[1]) | |
segments(index - 0.02, ci.mat[, 1], index + 0.02, ci.mat[, 1], lwd = line.width[2]) | |
segments(index - 0.02, ci.mat[, 3], index + 0.02, ci.mat[, 3], lwd = line.width[2]) | |
axis(1, index, labels=level.labels) | |
} | |
if(flip==TRUE){ | |
plot(0, 0, ylim = c(0.7, J + 0.3), yaxt = "n", xlim = y.lim , ylab = xlab, | |
xlab = ylab, main = main) | |
grid() | |
index <- 1:J | |
points(ci.mat[,2], index, pch = pch, bg = "black") | |
segments(ci.mat[, 1], index, ci.mat[, 3], index, lwd = line.width[1]) | |
segments( ci.mat[, 1], index - 0.02, ci.mat[, 1], index + 0.02, lwd = line.width[2]) | |
segments( ci.mat[, 3], index - 0.02, ci.mat[, 3], index + 0.02, lwd = line.width[2]) | |
axis(2, index, labels=level.labels) | |
} | |
} | |
plot.bsci(diag.dat, group.var=2, dv.var=4, ylab='Mean description quality', main = 'Difference-adjusted 95% CIs for the Diagram data', flip=TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment