This function is generic (see Methods); method functions can be written to handle specific classes of data. Classes which already have methods for this function include: default
Additional methods are defined by the module S+WAVELETS.
barplot(height, ...) barplot.default(height, width=<<see below>>, names=NULL, legend=NULL, style.bar=list(), space=.2, inside=T, beside=F, horiz=F, blocks=T, histo=F, axes=T, angle=<<see below>>, sbangle=45, dbangle=45, density=<<see below>>, sbdensity=5, dbdensity=5, col=<<see below>>, sbcol=2, dbcol=2:12)
Graphical parameters may also be supplied as arguments to this function (see par). In addition, the high-level graphics arguments described under par and the arguments to title may be supplied to this function. However, barplot will always use linear axes: the log and [xy]axt parameters do not affect it. You may transform your data, call barplot with axes=F, and then call axis with the at and labels arguments to make nonlinear axes that match your transformation. See the rootogram example below.
Occasionally the legend will overwrite a bar; if it does, use ylim (xlim if horiz=TRUE) to expand the axis.
To produce solid filling, specify col but neither angle or density. If you want to have both hatching and solid filling, specify density=0 for the solidly filled segments. Solid filling of bars is dependent on the area-filling capability of the device. For devices without explicit area-filling capability, solid filling can be simulated by specifying a very high density shading.
The sb* and db* arguments are primarily for use in style.bar argument lists, as is the use of NA for col and density argument values.
When using a height matrix of more than one row, the col, density and angle arguments can be specified either as vectors or as matrices having the same dimensions as the height matrix. As a matrix, each element specifies the attribute to be used for the block drawn from the corresponding element of the height matrix. As a vector, it is repeated (or truncated) to the number of rows in height. Using vectors for the attributes gives corresponding blocks in different bars the same attributes. Using matrices allows control of the attributes for all of the blocks in the barplot.
x <- barplot(height) # do plot, save x coordinates of bar centers text(x, height+1, height) # label the tops of the bars# a plot, sans labels and legend, using a style list bar.dbstyle <- list(dbangle=c(45, 135), dbdensity=(1:4)*6) barplot( t(telsam.response[1:5,]), ylim=c(0, 200), style="dbstyle")
# a similar plot, with hollow 1st block, solid 2nd block and density # set to 18 and 24 for the remaining 2 blocks bar.dbstyle <- list(dbangle=c(45, 135), dbdensity=c(-1, 0, 18, 24)) barplot( t(telsam.response[1:5,]), ylim=c(0, 200), style="dbstyle")
# the following rootogram function plots a histogram on a # square root scale rootogram <- function(x, ...) { h <- hist(x, ..., plot = F) h$counts <- sqrt(h$counts) barplot(height = h$counts, width = h$breaks, histo = T, axes = F) axis(side = 1) lab <- pretty(c(0, h$counts), par("lab")[2])^2 axis(side = 2, at = sqrt(lab), labels = as.character(lab), srt = if (par("las")==0) 90 else 0) invisible() }
barplot( t(telsam.response[1:5,]), ylim=c(0, 200), angle=c(45, 135), density=(1:4)*6, legend=dimnames(telsam.response)[[2]], names=as.character(dimnames(telsam.response)[[1]][1:5]), xlab="Interviewer", ylab="Number of Responses", main="Response to Quality of Service Question")