barplot(graphics)
barplot()所属R语言包:graphics
Bar Plots
条形图解
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Creates a bar plot with vertical or horizontal bars.
创建一个纵向或横向的条形的条形图。
用法----------Usage----------
barplot(height, ...)
## Default S3 method:[默认方法]
barplot(height, width = 1, space = NULL,
names.arg = NULL, legend.text = NULL, beside = FALSE,
horiz = FALSE, density = NULL, angle = 45,
col = NULL, border = par("fg"),
main = NULL, sub = NULL, xlab = NULL, ylab = NULL,
xlim = NULL, ylim = NULL, xpd = TRUE, log = "",
axes = TRUE, axisnames = TRUE,
cex.axis = par("cex.axis"), cex.names = par("cex.axis"),
inside = TRUE, plot = TRUE, axis.lty = 0, offset = 0,
add = FALSE, args.legend = NULL, ...)
参数----------Arguments----------
参数:height
either a vector or matrix of values describing the bars which make up the plot. If height is a vector, the plot consists of a sequence of rectangular bars with heights given by the values in the vector. If height is a matrix and beside is FALSE then each bar of the plot corresponds to a column of height, with the values in the column giving the heights of stacked sub-bars making up the bar. If height is a matrix and beside is TRUE, then the values in each column are juxtaposed rather than stacked.
无论是一个向量或矩阵描述值,从而弥补了图的条形。 height如果是一个向量,图组成的序列与向量的价值给予高度的矩形条。 height如果是一个矩阵,beside是FALSE然后每个条形的图对应的height列,列中的值的堆叠子给予高度的条形,条形。 height如果是一个矩阵,beside是TRUE,然后在每一列的值是并列的,而不是堆叠。
参数:width
optional vector of bar widths. Re-cycled to length the number of bars drawn. Specifying a single value will have no visible effect unless xlim is specified.
栏宽度可选向量。循环再用长度拉制的棒材数量。除非xlim指定指定一个单一的值不会有任何明显的效果。
参数:space
the amount of space (as a fraction of the average bar width) left before each bar. May be given as a single number or one number per bar. If height is a matrix and beside is TRUE, space may be specified by two numbers, where the first is the space between bars in the same group, and the second the space between the groups. If not given explicitly, it defaults to c(0,1) if height is a matrix and beside is TRUE, and to 0.2 otherwise.
空间(平均栏宽的一小部分),每个栏前离开。可作为一个单一的数量或每一个栏数。 height如果是一个矩阵,beside是TRUE,space可指定两个数字,其中第一个是在同一组的条形之间的空间,第二群体之间的空间。如果没有给出明确的,则默认为c(0,1)如果height是一个矩阵,besideTRUE,0.2,否则,。
参数:names.arg
a vector of names to be plotted below each bar or group of bars. If this argument is omitted, then the names are taken from the names attribute of height if this is a vector, or the column names if it is a matrix.
一个名字的向量绘制下面的每个条形或条形组。如果省略该参数,则名称names属性height如果这是一个向量,或列名,如果它是一个矩阵。
参数:legend.text
a vector of text used to construct a legend for the plot, or a logical indicating whether a legend should be included. This is only useful when height is a matrix. In that case given legend labels should correspond to the rows of height; if legend.text is true, the row names of height will be used as labels if they are non-null.
文本的向量,用于建设一个传奇的图,或逻辑指示是否应包括一个传奇。这是唯一有用的时候height是一个矩阵。在这种情况下,给出的图例标签应符合行height; legend.text如果是真实的,行名height将作为标签使用,如果他们非空。
参数:beside
a logical value. If FALSE, the columns of height are portrayed as stacked bars, and if TRUE the columns are portrayed as juxtaposed bars.
一个逻辑值。如果FALSE,列height被描绘成堆积条形图,如果TRUE列并列条形描绘。
参数:horiz
a logical value. If FALSE, the bars are drawn vertically with the first bar to the left. If TRUE, the bars are drawn horizontally with the first at the bottom.
一个逻辑值。如果FALSE,条形左侧第一栏绘制垂直。如果TRUE,条形水平制定的第一个底部。
参数:density
a vector giving the density of shading lines, in lines per inch, for the bars or bar components. The default value of NULL means that no shading lines are drawn. Non-positive values of density also inhibit the drawing of shading lines.
向量遮光线的密度,每英寸线,条形或条形组件。默认值NULL意味着没有阴影线绘制。 density非正面的价值观也抑制了阴影线绘图。
参数:angle
the slope of shading lines, given as an angle in degrees (counter-clockwise), for the bars or bar components.
遮光线的斜率,角度(逆时针),条形或条形组件。
参数:col
a vector of colors for the bars or bar components. By default, grey is used if height is a vector, and a gamma-corrected grey palette if height is a matrix.
的条形或条形组件的颜色向量。默认情况下,使用灰色height是一个向量,和伽玛校正的灰色调色板height如果是一个矩阵。
参数:border
the color to be used for the border of the bars. Use border = NA to omit borders. If there are shading lines, border = TRUE means use the same colour for the border as for the shading lines.
颜色可用于条形的边界。使用border = NA省略边框。如果有阴影线,border = TRUE意味着使用相同颜色的阴影线为边界。
参数:main,sub
overall and sub title for the plot.
图的整体和分标题。
参数:xlab
a label for the x axis.
为x轴的标签。
参数:ylab
a label for the y axis.
y轴的标签。
参数:xlim
limits for the x axis.
为x轴的限制。
参数:ylim
limits for the y axis.
为y轴的限制。
参数:xpd
logical. Should bars be allowed to go outside region?
逻辑。条形应该被允许以外的区域去吗?
参数:log
string specifying if axis scales should be logarithmic; see plot.default.
字符串,指定如果轴的尺度应该是数见plot.default。
参数:axes
logical. If TRUE, a vertical (or horizontal, if horiz is true) axis is drawn.
逻辑。如果TRUE,垂直(或水平,horiz如果是真实的)轴绘制。
参数:axisnames
logical. If TRUE, and if there are names.arg (see above), the other axis is drawn (with lty=0) and labeled.
逻辑。如果TRUE,如果有names.arg(见上文),其他的轴画(用lty=0)和标记。
参数:cex.axis
expansion factor for numeric axis labels.
膨胀系数的数值轴标签。
参数:cex.names
expansion factor for axis names (bar labels).
轴名称(栏标签)的膨胀系数。
参数:inside
logical. If TRUE, the lines which divide adjacent (non-stacked!) bars will be drawn. Only applies when space = 0 (which it partly is when beside = TRUE).
逻辑。如果TRUE,将绘制线划分相邻(non-stacked!)的条形。只适用于当space = 0(这部分是当beside = TRUE)。
参数:plot
logical. If FALSE, nothing is plotted.
逻辑。如果FALSE,没有绘制。
参数:axis.lty
the graphics parameter lty applied to the axis and tick marks of the categorical (default horizontal) axis. Note that by default the axis is suppressed.
图形参数lty申请类别(默认水平)轴的轴和刻度。请注意,默认情况下,轴被抑制。
参数:offset
a vector indicating how much the bars should be shifted relative to the x axis.
矢量显示多少条应转向相对x轴。
参数:add
logical specifying if bars should be added to an already existing plot; defaults to FALSE.
指定如果条形应该被添加到一个已经存在的图;默认FALSE逻辑。
参数:args.legend
list of additional arguments to pass to legend(); names of the list are used as argument names. Only used if legend.text is supplied.
额外的参数列表传递给legend();列表的名称作为参数名。只用了如果legend.text提供。
参数:...
arguments to be passed to/from other methods. For the default method these can include further arguments (such as axes, asp and main) and graphical parameters (see par) which are passed to plot.window(), title() and axis.
参数被传递到/从其他方法。对于默认的方法,这些可以包括进一步的参数(如axes,asp和main)和图形参数(见par)传递plot.window()的 title()和axis。
Details
详情----------Details----------
This is a generic function, it currently only has a default method. A formula interface may be added eventually.
这是一个通用的功能,目前只有一个默认的方法。最终可能会增加一个公式界面。
值----------Value----------
A numeric vector (or matrix, when beside = TRUE), say mp, giving the coordinates of all the bar midpoints drawn, useful for adding to the graph.
一个数值向量(或矩阵,当beside = TRUE),说mp,让所有的条形的中点,用于增加图的坐标。
If beside is true, use colMeans(mp) for the midpoints of each group of bars, see example.
beside如果是真实的,使用colMeans(mp)各组条形的中点,见示例。
参考文献----------References----------
The New S Language. Wadsworth & Brooks/Cole.
参见----------See Also----------
plot(..., type="h"), dotchart, hist.
plot(..., type="h"),dotchart,hist。
举例----------Examples----------
require(grDevices) # for colours[对色彩]
tN <- table(Ni <- stats::rpois(100, lambda=5))
r <- barplot(tN, col=rainbow(20))
#- type = "h" plotting *is* 'bar'plot[ - 类型=“H”图*是*barplot]
lines(r, tN, type='h', col='red', lwd=2)
barplot(tN, space = 1.5, axisnames=FALSE,
sub = "barplot(..., space= 1.5, axisnames = FALSE)")
barplot(VADeaths, plot = FALSE)
barplot(VADeaths, plot = FALSE, beside = TRUE)
mp <- barplot(VADeaths) # default[默认]
tot <- colMeans(VADeaths)
text(mp, tot + 3, format(tot), xpd = TRUE, col = "blue")
barplot(VADeaths, beside = TRUE,
col = c("lightblue", "mistyrose", "lightcyan",
"lavender", "cornsilk"),
legend = rownames(VADeaths), ylim = c(0, 100))
title(main = "Death Rates in Virginia", font.main = 4)
hh <- t(VADeaths)[, 5:1]
mybarcol <- "gray20"
mp <- barplot(hh, beside = TRUE,
col = c("lightblue", "mistyrose",
"lightcyan", "lavender"),
legend = colnames(VADeaths), ylim= c(0,100),
main = "Death Rates in Virginia", font.main = 4,
sub = "Faked upper 2*sigma error bars", col.sub = mybarcol,
cex.names = 1.5)
segments(mp, hh, mp, hh + 2*sqrt(1000*hh/100), col = mybarcol, lwd = 1.5)
stopifnot(dim(mp) == dim(hh))# corresponding matrices[相应的矩阵]
mtext(side = 1, at = colMeans(mp), line = -2,
text = paste("Mean", formatC(colMeans(hh))), col = "red")
# Bar shading example[条形阴影的例子]
barplot(VADeaths, angle = 15+10*1:5, density = 20, col = "black",
legend = rownames(VADeaths))
title(main = list("Death Rates in Virginia", font = 4))
# border :[边框:]
barplot(VADeaths, border = "dark blue")
# log scales (not much sense here):[日志尺度(在这里没有太大的意义):]
barplot(tN, col=heat.colors(12), log = "y")
barplot(tN, col=gray.colors(20), log = "xy")
# args.legend[args.legend]
barplot(height = cbind(x = c(465, 91) / 465 * 100,
y = c(840, 200) / 840 * 100,
z = c(37, 17) / 37 * 100),
beside = FALSE,
width = c(465, 840, 37),
col = c(1, 2),
legend.text = c("A", "B"),
args.legend = list(x = "topleft"))
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|