Boxplot

From Christoph's Personal Wiki
Jump to: navigation, search

In descriptive statistics, a boxplot (also known as a box-and-whisker diagram or plot) is a convenient way of graphically depicting groups of numerical data through their five-number summaries (the smallest observation, lower quartile (Q1), median (Q2), upper quartile (Q3), and largest observation). A boxplot may also indicate which observations, if any, might be considered outliers.

This article will various practical ways of creating boxplots using the R programming language.

Filetypes

svg(file = "foo.svg", width = 2.5, height = 5, pointsize = 8)
postscript("foo.ps", paper="special", height=6, width=6, horizontal=F)
pdf("foo.pdf", height=6, width=6)

Example-01

data(morley)
morley$Expt <- factor(morley$Expt)
morley$Run <- factor(morley$Run)
attach(morley)

postscript("Michelsonmorley-boxplot.ps", paper="special", height=6, width=6,
           horizontal=F)
par(las=1)
par(mar=c(5.1, 5.1, 2.1, 2.1))
par(font=2)
par(font.axis=2)
boxplot(Speed ~ Expt, xlab = "Experiment No.", ylab="Speed of light (km/s minus 299,000)")
abline(h=792.458, lty=3)
dev.off()
  • Another way to do the same thing:
data(morley)
morley$Expt <- factor(morley$Expt)

pdf("Michelsonmorley-boxplot.pdf", height=6, width=6)
par(las=1, mar=c(5.1, 5.1, 2.1, 2.1))
boxplot(Speed ~ Expt, morley, xlab = "Experiment No.",
        ylab="Speed of light (km/s minus 299,000)")
abline(h=792.458, col="red")
text(3,792.458,"true\nspeed")
dev.off()

External links