Barplot
barplot(height)
where height
is vector or matrix |
Options: horiz=TRUE
, main
, xlab
, ylab
, names.arg
|
If height
is matrix, stacked and grouped bar plot is produced |
Options: beside=TRUE
, col
, legend
|
If height
is factor or ordered factor, use plot()
function |
Spinograms
spine()
function in vcd
package |
Fan plot
fan.plot()
in plotrix
package |
|
|
Box plots
Five-number summary Minimum, lower quartile (25th percentile), median (50th percentile), upper quartile (75th percentile), maximum
|
Outliers Values outside the range of +- 1.5*IQR
|
Example boxplot(mtcars$mpg, main="Box plot", ylab="Miles per Galleons")
|
boxplot.stats(mtcars$mpg)
|
Parallel box plots for comparison boxplot(formula, data=dataframe)
|
Box plots
boxplot(mpg ~ cyl, data=mtcars, main="Car Mileage Data", xlab="Number of Cylinders", ylab="Miles per Gallon")
Box plots
boxplot(mpg ~ cyl, data=mtcars, notch=TRUE, varwidth=TRUE, col="red", main="Car Mileage Data", xlab="Number of Cylinders", ylab="Miles per Gallon")
|
|
Box plots (2 crossed factors)
Box plots (2 crossed factors)
Violin plots
Violin plots are kernel density plots superimposed in a mirror image fashion over box plots |
vioplot(x1, x2, … , names=, col=)
|
Violin plots
library(vioplot)
x1 <- mtcars$mpg[mtcars$cyl==4]
x2 <- mtcars$mpg[mtcars$cyl==6]
x3 <- mtcars$mpg[mtcars$cyl==8]
vioplot(x1, x2, x3, names=c("4 cyl", "6 cyl", "8 cyl"), col="gold")
title("Violin Plots of Miles Per Gallon")
Dot plots
dotchart(mtcars$mpg, labels=row.names(mtcars), cex=.7, main="Gas Mileage for Car Models", xlab="Miles Per Gallon")
Dot plots - grouped, sorted and colored
x <- mtcars[order(mtcars$mpg),]
x$cyl <- factor(x$cyl)
x$color[x$cyl==4] <- "red"
x$color[x$cyl==6] <- "blue"
x$color[x$cyl==8] <- "darkgreen"
dotchart(x$mpg, labels = row.names(x), cex=.7, groups = x$cyl, gcolor = "black", color = x$color, pch=19, main = "Gas Mileage for Car Models\ngrouped by cylinder", xlab = "Miles Per Gallon")
|