當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R bxp 從摘要中繪製箱線圖

R語言 bxp 位於 graphics 包(package)。

說明

bxp 根據 z 中給定的摘要繪製箱線圖。它通常從 boxplot 內部調用,但也可以直接調用。

用法

bxp(z, notch = FALSE, width = NULL, varwidth = FALSE,
    outline = TRUE, notch.frac = 0.5, log = "",
    border = par("fg"), pars = NULL, frame.plot = axes,
    horizontal = FALSE, ann = TRUE,
    add = FALSE, at = NULL, show.names = NULL,
    ...)

參數

z

包含用於構建繪圖的數據摘要的列表。這些通常是調用 boxplot 的結果,但可以以任何方式生成。

notch

如果 notchTRUE ,則在框的每一側繪製一個凹口。如果兩個圖的缺口不重疊,則中位數在 5% 的水平上顯著不同。

width

給出構成繪圖的框的相對寬度的向量。

varwidth

如果 varwidthTRUE ,則繪製框的寬度與組中觀測值數量的平方根成正比。

outline

如果 outline 不為 true,則不會繪製異常值。

notch.frac

(0,1) 中的數字。當 notch = TRUE 時,凹口應使用的框寬度的分數。

border

字符或數字(向量),框邊框的顏色。可回收用於多個盒子。用作 boxcolmedcolwhiskcolstaplecoloutcol 選項的默認值(見下文)。

log

字符,指示是否應以對數刻度繪製任何軸,如 plot.default 中。

frame.plot

邏輯,指示是否應繪製‘frame’(box);默認為 TRUE ,除非指定 axes = FALSE

horizontal

邏輯表明箱線圖是否應該是水平的;默認FALSE表示垂直框。

ann

一個邏輯值,指示默認注釋(標題以及 x 和 y 軸標簽)是否應出現在繪圖上。

add

邏輯,如果 true 將箱線圖添加到當前繪圖。

at

給出應繪製箱線圖的位置的數值向量,特別是當 add = TRUE 時;默認為1:n,其中n 是盒子的數量。

show.names

設置為 TRUEFALSE 以覆蓋是否為每個組打印 x 軸標簽的默認值。

pars,...

graphical parameters (等)可以作為參數傳遞給此函數,可以作為列表( pars )或通常( ... ),請參閱以下內容。 (... 中的內容優先於 pars 中的內容。)

現在,yaxsylim“沿箱線圖”使用,即垂直使用,當horizontal是假的,並且xlim水平地。xaxt,yaxt,las,cex.axis,gap.axis, 和col.axis被傳遞給axis, 和main,cex.main,col.main,sub,cex.sub,col.sub,xlab,ylab,cex.lab, 和col.lab被傳遞給title.

此外,接受 axes (請參閱 plot.window ),默認為 TRUE

以下參數(或 pars 組件)允許進一步自定義箱線圖圖形。它們的默認值通常是根據無前綴版本(例如, lty 中的 boxlty )確定的,可以根據指定的參數或 pars 組件或相應的 par 組件確定。

盒子維克斯:

應用於所有框的比例因子。當隻有幾個組時,可以通過使框變窄來改善繪圖的外觀。默認值取決於at,通常為

釘書釘,外釘書釘:

訂書釘和離群線寬度擴展,與盒子寬度成正比;兩者都默認為 0.5。

boxlty、boxlwd、boxcol、boxfill:

框輪廓類型、寬度、顏色和填充顏色(當前默認為 col ,將來默認為 par("bg") )。

medlty、medlwd、medpch、medcex、medcol、medbg:

中線類型、線寬、點字符、點大小擴展、顏色和背景顏色。默認medpch = NA 會抑製點,medlty = "blank" 則會抑製線。請注意, medlwd 默認為 默認為 lwd

威士忌蒂、威士忌lwd、威士忌科爾:

須線類型(默認值:"dashed")、寬度和顏色。

staplelty、staplelwd、staplecol:

訂書釘(=須的末端)線條類型、寬度和顏色。

outlty、outlwd、outpch、outcex、outcol、outbg:

離群線類型、線寬、點字符、點尺寸擴展、顏色和背景顏色。默認outlty = "blank" 抑製線,outpch = NA 抑製點。

一個不可見的向量,實際上與 at 參數相同,具有框中心的坐標(如果水平為 false,則為 "x",否則為 "y"),可用於添加到繪圖中。

注意

add = FALSE 時,xlim 現在默認為 xlim = range(at, *) + c(-0.5, 0.5) 。如果 "x" 軸具有對數刻度或 width 遠不均勻,則通常最好指定 xlim

例子

require(stats)
set.seed(753)
(bx.p <- boxplot(split(rt(100, 4), gl(5, 20))))
op <- par(mfrow =  c(2, 2))
bxp(bx.p, xaxt = "n")
bxp(bx.p, notch = TRUE, axes = FALSE, pch = 4, boxfill = 1:5)
bxp(bx.p, notch = TRUE, boxfill = "lightblue", frame.plot = FALSE,
    outline = FALSE, main = "bxp(*, frame.plot= FALSE, outline= FALSE)")
bxp(bx.p, notch = TRUE, boxfill = "lightblue", border = 2:6,
    ylim = c(-4,4), pch = 22, bg = "green", log = "x",
    main = "... log = 'x', ylim = *")
par(op)
op <- par(mfrow = c(1, 2))

## single group -- no label
boxplot (weight ~ group, data = PlantGrowth, subset = group == "ctrl")
## with label
bx <- boxplot(weight ~ group, data = PlantGrowth,
              subset = group == "ctrl", plot = FALSE)
bxp(bx, show.names=TRUE)
par(op)

## passing gap.axis=* to axis(), PR#18109:
boxplot(matrix(100*rnorm(1e3), 50, 20),
        cex.axis = 1.5, gap.axis = -1)# showing *all* labels


z <- split(rnorm(1000), rpois(1000, 2.2))
boxplot(z, whisklty = 3, main = "boxplot(z, whisklty = 3)")

## Colour support similar to plot.default:
op <- par(mfrow = 1:2, bg = "light gray", fg = "midnight blue")
boxplot(z,   col.axis = "skyblue3", main = "boxplot(*, col.axis=..,main=..)")
plot(z[[1]], col.axis = "skyblue3", main =    "plot(*, col.axis=..,main=..)")
mtext("par(bg=\"light gray\", fg=\"midnight blue\")",
      outer = TRUE, line = -1.2)
par(op)

## Mimic S-Plus:
splus <- list(boxwex = 0.4, staplewex = 1, outwex = 1, boxfill = "grey40",
              medlwd = 3, medcol = "white", whisklty = 3, outlty = 1, outpch = NA)
boxplot(z, pars = splus)
## Recycled and "sweeping" parameters
op <- par(mfrow = c(1,2))
 boxplot(z, border = 1:5, lty = 3, medlty = 1, medlwd = 2.5)
 boxplot(z, boxfill = 1:3, pch = 1:5, lwd = 1.5, medcol = "white")
par(op)
## too many possibilities
boxplot(z, boxfill = "light gray", outpch = 21:25, outlty = 2,
        bg = "pink", lwd = 2,
        medcol = "dark blue", medcex = 2, medpch = 20)

作者

The R Core development team and Arni Magnusson (then at U Washington) who has provided most changes for the box*, med*, whisk*, staple*, and out* arguments.

參考

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.

相關用法


注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Draw Box Plots from Summaries。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。