boxplot() 箱线图
(2016-06-08 09:20:34)| 标签: r语言boxplot()箱线图 | 分类: R语言学习 | 
| boxplot {graphics} | R Documentation | 
Box Plots
Description
Produce box-and-whisker plot(s) of the given (grouped) values.
Usage
boxplot(x, ...)
## S3 method for class 'formula'
boxplot(formula, data = NULL, ..., subset, na.action = NULL)
## Default S3 method:
boxplot(x, ..., range = 1.5, width = NULL, varwidth = FALSE,
        notch = FALSE, outline = TRUE, names, plot = TRUE,
        border = par("fg"), col = NULL, log = "",
        pars = list(boxwex = 0.8, staplewex = 0.5, outwex = 0.5),
        horizontal = FALSE, add = FALSE, at = NULL)
Arguments
| formula | 类似y~grp这样的公式,其中y是要画的变量,grp是描述分组的变量 | 
| data | 数据框或列表,其中定义了formula所使用的变量. | 
| subset | 向量,设置用于画图的子集. | 
| na.action | a function which
indicates what should happen when the data contain  | 
| x | 向量,设置用于画图的值. | 
| ... | 其他绘图参数. | 
| range | 数值,定义从箱子延伸出来的胡须的最大长度. | 
| width | 数值向量,设置箱子的宽度. | 
| varwidth | 若=TRUE,每个盒子的宽度与盒子所表示的观察数的平方根相关。若=FALSE,则所有盒子的宽度都是一样的. | 
| notch | 若=TRUE,就会在箱子上画一个缺口。. | 
| outline | 逻辑值,是否要画出异常值 | 
| names | 字符向量,设置每个箱线图的标签 | 
| boxwex | a scale factor to be applied to all boxes. When there are only a few groups, the appearance of the plot can be improved by making the boxes narrower. | 
| staplewex | staple line width expansion, proportional to box width. | 
| outwex | outlier line width expansion, proportional to box width. | 
| plot | 若=TRUE,画箱线图,若=FALSE,则返回用于画箱线图的统计量,但不画图. | 
| border | 设置箱线图外框的颜色. | 
| col | 字符向量,设置每个箱线图的背景色. | 
| log | 字符,设置是否需要做对数变换. | 
| pars | 传递给bxp的图形参数. | 
| horizontal | 逻辑值,设置箱子是横向的还是纵向的. | 
| add | 逻辑值,谁知箱子是否画到现有的图上. | 
| at | 数值向量,设置箱线图的位置. | 
See Also
boxplot.stats bxp stripchart 
Examples
## boxplot on a formula:
boxplot(count ~ spray, data = InsectSprays, col = "lightgray")
# *add* notches (somewhat funny here):
boxplot(count ~ spray, data = InsectSprays,
        notch = TRUE, add = TRUE, col = "blue")
boxplot(decrease ~ treatment, data = OrchardSprays,
        log = "y", col = "bisque")
rb <- boxplot(decrease ~ treatment, data = OrchardSprays, col = "bisque")
title("Comparing boxplot()s and non-robust mean +/- SD")
mn.t <- tapply(OrchardSprays$decrease, OrchardSprays$treatment, mean)
sd.t <- tapply(OrchardSprays$decrease, OrchardSprays$treatment, sd)
xi <- 0.3 + seq(rb$n)
points(xi, mn.t, col = "orange", pch = 18)
arrows(xi, mn.t - sd.t, xi, mn.t + sd.t,
       code = 3, col = "pink", angle = 75, length = .1)
## boxplot on a matrix:
mat <- cbind(Uni05 = (1:100)/21, Norm = rnorm(100),
             `5T` = rt(100, df = 5), Gam2 = rgamma(100, shape = 2))
boxplot(as.data.frame(mat),
        main = "boxplot(as.data.frame(mat), main = ...)")
par(las = 1) # all axis labels horizontal
boxplot(as.data.frame(mat), main = "boxplot(*, horizontal = TRUE)",
        horizontal = TRUE)
## Using 'at = ' and adding boxplots -- example idea by Roger Bivand :
boxplot(len ~ dose, data = ToothGrowth,
        boxwex = 0.25, at = 1:3 - 0.2,
        subset = supp == "VC", col = "yellow",
        main = "Guinea Pigs' Tooth Growth",
        xlab = "Vitamin C dose mg",
        ylab = "tooth length",
        xlim = c(0.5, 3.5), ylim = c(0, 35), yaxs = "i")
boxplot(len ~ dose, data = ToothGrowth, add = TRUE,
        boxwex = 0.25, at = 1:3 + 0.2,
        subset = supp == "OJ", col = "orange")
legend(2, 9, c("Ascorbic acid", "Orange juice"),
       fill = c("yellow", "orange"))
## more examples in  help(bxp)

 加载中…
加载中…