library(MASS)
data(cats)
summary(cats)
## Sex Bwt Hwt
## F:47 Min. :2.000 Min. : 6.30
## M:97 1st Qu.:2.300 1st Qu.: 8.95
## Median :2.700 Median :10.10
## Mean :2.724 Mean :10.63
## 3rd Qu.:3.025 3rd Qu.:12.12
## Max. :3.900 Max. :20.50
t.test(Bwt ~ Sex, data = cats)
##
## Welch Two Sample t-test
##
## data: Bwt by Sex
## t = -8.7095, df = 136.84, p-value = 8.831e-15
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.6631268 -0.4177242
## sample estimates:
## mean in group F mean in group M
## 2.359574 2.900000
t.test.out <- t.test(Bwt ~ Sex, data = cats)
means <- t.test.out$estimate
diff <- means[1]-means[2]
CI <- t.test.out$conf.int
Use gplots::plotCI()
library(gplots)
##
## Attaching package: 'gplots'
## The following object is masked from 'package:stats':
##
## lowess
plotCI(x = diff,
li = CI[1],
ui = CI[2])
par(xaxt='n')
plotCI(x = diff,
li = CI[1],
ui = CI[2])
par(xaxt='t')
plotCI(x = diff,
li = CI[1],
ui = CI[2])
par(xaxt='n')
plotCI(x = diff,
li = CI[1],
ui = CI[2],
xlab = "",
ylab = "Effect Size")
par(xaxt='n')
plotCI(x = diff,
li = CI[1],
ui = CI[2],
xlab = "",
ylab = "Effect Size")
text(x = 0.56, y = -0.45,
pos = 4,
label = "Error bars = +/- 95% CI")
#set par() in case not already set
par(xaxt='n')
#The plot
plotCI(x = diff,
li = CI[1],
ui = CI[2],
xlab = "",
ylab = "Effect Size")
#The label
mtext(text = "Error bars = +/- 95% CI",
side = 3,
adj = 0,
line = -1)
#set margins
par(mar = c(1,4,1,1))
#plot
plotCI(x = diff,
li = CI[1],
ui = CI[2],
xlab = "",
ylab = "Effect Size")
#label
mtext(text = "Error bars = +/- 95% CI",
side = 3,
adj = 0,
line = -1)
#Set part
par(mar = c(1,3,1,1))
#plot
plotCI(x = diff,
li = CI[1],
ui = CI[2],
xlab = "",
ylab = "") #get rid of ylab
#new label for y axis
mtext(text = "Effect size", side = 2, line = 2)
#annotation about error bars
mtext(text = "Error bars = +/- 95% CI",
side = 3,
adj = 0,
line = -1)
par(mar = c(1,3,1,1))
plotCI(x = diff,
ylim = c(-0.75,0.1),
li = CI[1],
ui = CI[2],
xlab = "",
ylab = "") #get rid of ylab
mtext(text = "Effect size", side = 2, line = 2)
#annotation about error bars
mtext(text = "Error bars = +/- 95% CI",
side = 3,
adj = 0,
line = -1)
par(mar = c(1,3,1,1))
plotCI(x = diff,
ylim = c(-0.75,0.1),
li = CI[1],
ui = CI[2],
xlab = "",
ylab = "") #get rid of ylab
#add reference line
abline(h = 0, col = 2, lty = 2)
# y axis label
mtext(text = "Effect size", side = 2, line = 2)
#annotation about error bars
mtext(text = "Error bars = +/- 95% CI",
side = 3,
adj = 0,
line = -1)