# simulate data and get at least one outlier
y <- rnorm(100,50,10)
y[1] <- 90
# -----------------------------
# boxplot for a single variable
# -----------------------------
# standard horizontal boxplot with all defaults
BoxPlot(y)
# short name
bx(y)
# vertical boxplot with plum color
BoxPlot(y, horiz=FALSE, col.box="plum")
# boxplot with outliers more strongly highlighted
BoxPlot(y, col.pts="red", xlab="My Variable")
# -----------------------------------------------
# boxplots for data frames and multiple variables
# -----------------------------------------------
# create data frame, mydata, to mimic reading data with rad function
# mydata contains both numeric and non-numeric data
mydata <- data.frame(rnorm(100), rnorm(100), rnorm(100), rep(c("A","B"),50))
names(mydata) <- c("X","Y","Z","C")
# boxplot for variable X from data frame, referred to directly
BoxPlot(X)
# boxplot with superimposed dot plot (stripchart)
BoxPlot(X, dotplot=TRUE)
# boxplots for all numeric variables in data frame called mydata
BoxPlot()
# boxplots for all numeric variables in data frame called mydata
# with specified options
BoxPlot(col.box="palegreen1", col.pts="plum")
# Use the subset function to specify a variable list
mysub <- subset(mydata, select=c(X,Y))
BoxPlot(dframe=mysub)
Run the code above in your browser using DataLab