-
Notifications
You must be signed in to change notification settings - Fork 0
/
myboxplot.R
51 lines (51 loc) · 1.73 KB
/
myboxplot.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
myboxplot=function (x, ..., range = 1.5, width = NULL, varwidth = FALSE,
notch = FALSE, outline = TRUE, names, boxwex = 0.8, plot = TRUE,
border = par("fg"), col = "cornflowerblue", log = "", pars = NULL, horizontal = FALSE,
add = FALSE, at = NULL) #col was NULL
{
args <- list(x, ...)
namedargs <- if (!is.null(attributes(args)$names))
attributes(args)$names != ""
else rep(FALSE, length.out = length(args))
pars <- c(args[namedargs], pars)
groups <- if (is.list(x))
x
else args[!namedargs]
if (0 == (n <- length(groups)))
stop("invalid first argument")
if (length(class(groups)))
groups <- unclass(groups)
if (!missing(names))
attr(groups, "names") <- names
else {
if (is.null(attr(groups, "names")))
attr(groups, "names") <- 1:n
names <- attr(groups, "names")
}
for (i in 1:n) groups[i] <- list(myboxplot.stats(groups[[i]],
range))
stats <- matrix(0, nr = 5, nc = n)
conf <- matrix(0, nr = 2, nc = n)
ng <- out <- group <- numeric(0)
ct <- 1
for (i in groups) {
stats[, ct] <- i$stats
conf[, ct] <- i$conf
ng <- c(ng, i$n)
if ((lo <- length(i$out))) {
out <- c(out, i$out)
group <- c(group, rep.int(ct, lo))
}
ct <- ct + 1
}
z <- list(stats = stats, n = ng, conf = conf, out = out,
group = group, names = names)
if (plot) {
bxp(z, width, varwidth = varwidth, notch = notch, boxwex = boxwex,
border = border, col = col, log = log, pars = pars,
outline = outline, horizontal = horizontal, add = add,
at = at)
invisible(z)
}
else z
}