require(gplots) #for smartlegend data(ToothGrowth) boxplot(len ~ dose, data = ToothGrowth, boxwex = 0.25, at = 1:3 - 0.2, subset= supp == "VC", col="yellow", main="Guinea Pigs' Tooth Growth", xlab="Vitamin C dose mg", ylab="tooth length", ylim=c(0,35)) boxplot(len ~ dose, data = ToothGrowth, add = TRUE, boxwex = 0.25, at = 1:3 + 0.2, subset= supp == "OJ", col="orange") smartlegend(x="left",y="top", inset = 0, c("Ascorbic acid", "Orange juice"), fill = c("yellow", "orange")) a <- c(10,2,3,4,5,9) b <- c(10,45,8,1,1,6) z <- data.frame(a,b) boxplot(z)