-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotTukeyHSD.function.R
85 lines (66 loc) · 2.18 KB
/
plotTukeyHSD.function.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# means = 3 mean values calcualted from raw data
# se = 3 standard errors
# categories = 3 categorical / factors that group the data
# x.axis.label = what should be plotted on the x axis
# y.axis.label = what should be plotted on the y axis
#### The function STARTS here ####
plotTukeyHSD <- plotTukeysHSD <- function(tukey.out,
x.axis.label = "Comparison",
y.axis.label = "Effect Size",
axis.adjust = 0,
adjust.x.spacing = 5){
tukey.out <- as.data.frame(tukey.out[[1]])
means <- tukey.out$diff
categories <- row.names(tukey.out)
groups <- length(categories)
ci.low <- tukey.out$lwr
ci.up <- tukey.out$upr
n.means <- length(means)
#determine where to plot points along x-axis
x.values <- 1:n.means
x.values <- x.values/adjust.x.spacing
# calculate values for plotting limits
y.max <- max(ci.up) +
max(ci.up)*axis.adjust
y.min <- min(ci.low) -
max(ci.low)*axis.adjust
if(groups == 2){ x.values <- c(0.25, 0.5)}
if(groups == 3){ x.values <- c(0.25, 0.5,0.75)}
x.axis.min <- min(x.values)-0.05
x.axis.max <- max(x.values)+0.05
x.limits <- c(x.axis.min,x.axis.max)
#Plot means
plot(means ~ x.values,
xlim = x.limits,
ylim = c(y.min,y.max),
xaxt = "n",
xlab = "",
ylab = "",
cex = 1.25,
pch = 16)
axis(side = 1,
at = x.values,
labels = categories,
)
#Plot upper error bar
lwd. <- 2
arrows(y0 = means,
x0 = x.values,
y1 = ci.up,
x1 = x.values,
length = 0,
lwd = lwd.)
#Plot lower error bar
arrows(y0 = means,
x0 = x.values,
y1 = ci.low,
x1 = x.values,
length = 0,
lwd = lwd.)
#add reference line at 0
abline(h = 0, col = 2, lwd = 2, lty =2)
mtext(text = x.axis.label,side = 1,line = 1.75)
mtext(text = y.axis.label,side = 2,line = 1.95)
mtext(text = "Error bars = 95% CI",side = 3,line = 0,adj = 0)
}
#### The function ENDS here ####