R: Plotting Factor Variables (original) (raw)

plot.factor {graphics} R Documentation

Description

This method is used for[factor](../../base/html/factor.html) arguments of the generic [plot](../../graphics/help/plot.html) function, possibly called from the formula method.

If y is missing a [barplot](../../graphics/help/barplot.html) is produced. For numeric y a [boxplot](../../graphics/help/boxplot.html) is used, and for a factory a [spineplot](../../graphics/help/spineplot.html) is shown. For any other type ofy the next plot method is called, normally[plot.default](../../graphics/help/plot.default.html).

Usage

## S3 method for class 'factor'
plot(x, y, legend.text = NULL, ...)

Arguments

x, y numeric or factor. y may be missing.
legend.text character vector for annotation of y axis in the case of a factor y: defaults to levels(y). This sets the yaxlabels argument of spineplot.
... Further arguments to barplot,boxplot, spineplot orplot as appropriate. All of these acceptgraphical parameters (see par), annotation arguments passed to title, and axes = FALSE. None accept type.

See Also

[plot.default](../../graphics/help/plot.default.html), [plot.formula](../../graphics/help/plot.formula.html),[barplot](../../graphics/help/barplot.html), [boxplot](../../graphics/help/boxplot.html), [spineplot](../../graphics/help/spineplot.html).

Examples

require(grDevices)

plot(state.region)

## called from the formula method
plot(~ group, data = PlantGrowth)
plot(weight ~ group, data = PlantGrowth)           # numeric ~ factor
plot(cut(weight, 2) ~ group, data = PlantGrowth)   # factor ~ factor
## passing "..." to spineplot() eventually:
plot(cut(weight, 3) ~ group, data = PlantGrowth,
     col = hcl(c(0, 120, 240), 50, 70))

plot(PlantGrowth$group, axes = FALSE, main = "no axes")  # extremely silly

[Package _graphics_ version 4.6.0 Index]