par(mfrow=c(2,2))#
histPlot(tips$tip[tips$day == 'Tuesday'], hollow=TRUE, xlim=c(0, 30))#
histPlot(tips$tip[tips$day == 'Friday'], hollow=TRUE, border='red', add=TRUE)#
densityPlot(tips$tip, tips$day, col=c('black', 'red'))#
legend('topright', col=c('#882233','#223388'), lty=1:2, legend=c('Tuesday', 'Friday'))#
data(run10)#
densityPlot(run10$time, histo='faded', breaks=15)#
densityPlot(run10$time, histo='outline', breaks=30, fadingBorder='66', lty=1)
par(mfrow=c(2,2))#
histPlot(tips$tip[tips$day == 'Tuesday'], hollow=TRUE, xlim=c(0, 30), lty=1)#
histPlot(tips$tip[tips$day == 'Friday'], hollow=TRUE, border='red', add=TRUE)#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
densityPlot(tips$tip, tips$day, col=c('black', 'red'))#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
data(run10)#
densityPlot(run10$time, histo='faded', breaks=15)#
densityPlot(run10$time, histo='outline', breaks=30, fadingBorder='66', lty=1)
`densityPlot` <-#
function(x, fact=NULL, bw = "nrd0", histo=c('none', 'faded', 'hollow'), breaks='Sturges', fading='0E', fadingBorder='25', lty=NULL, lwd=1, col=c('#882233','#223388','#666611'), key=NULL, add=FALSE, adjust = 1, kernel = c("gaussian", "epanechnikov", "rectangular","triangular", "biweight", "cosine", "optcosine"), weights = NULL, n = 512, from, to, na.rm = FALSE, xlim=NULL, ylim=NULL, main=''){#
	if(!is.null(fact)[1]){#
		d <- list()#
		fact <- as.character(fact)#
		if(is.null(key)[1]){#
			key <- unique(fact)#
		}#
		K <- length(key)#
		if(is.null(lty)[1]){#
			lty <- 1:K#
		}#
		if(is.null(lwd)[1]){#
			lwd <- rep(1,K)#
		}#
		xR <- NULL#
		yR <- NULL#
		for(i in 1:K){#
			d[[i]] <- density(x[fact == key[i]],#
				bw=bw, adjust=adjust, kernel=kernel,#
				weights=weights, n=n, from=from, to=to,#
				na.rm=na.rm)#
			xR <- range(c(xR, d[[i]]$x))#
			yR <- max(c(yR, max(d[[i]]$y)))#
		}#
		if(is.null(xlim)[1]){#
			xlim <- xR#
		}#
		if(is.null(ylim)[1]){#
			ylim <- c(0,yR)#
		}#
		if(add){#
			for(i in 1:K){#
				densityPlot(x[fact==key[i]], add=TRUE,#
					col=col[i], lty=lty[i], lwd=lwd[i],#
					xlim=xlim, ylim=ylim)#
			}#
		} else {#
			densityPlot(x[fact==key[1]], add=FALSE,#
				col=col[1], lty=lty[1], lwd=lwd[1],#
				xlim=xlim, ylim=ylim)#
			if(K > 1){#
				for(i in 2:K){#
					densityPlot(x[fact==key[i]], add=TRUE,#
						col=col[i], lty=lty[i], lwd=lwd[i])#
				}#
			}#
		}#
	} else {#
		K <- 1#
		d <- density(x, bw=bw, adjust=adjust, kernel=kernel,#
			weights=weights, n=n, from=from, to=to, na.rm=na.rm)#
		xR <- range(d$x)#
		yR <- max(d$y)#
		if(histo[1] %in% c('hollow', 'faded')){#
			H <- hist(x, breaks=breaks, plot=FALSE)#
			xR <- range(c(xR, H$breaks))#
			yR <- max(c(yR, max(H$density)))#
		}#
		if(is.null(xlim)[1]){#
			xlim <- xR#
		}#
		if(is.null(ylim)[1]){#
			ylim <- c(0,yR)#
		}#
		if(histo[1]=='hollow'){#
			histPlot(x, col=fadeColor(col[1],fading),#
				border=fadeColor(col[1],fadingBorder),#
				breaks=breaks, probability=TRUE,#
				add=add, xlim=xlim, ylim=ylim, main=main,#
				hollow=TRUE)#
		} else if(histo[1]=='faded'){#
			histPlot(x, col=fadeColor(col[1],fading),#
				border=fadeColor(col[1],fadingBorder),#
				breaks=breaks, probability=TRUE,#
				add=add, xlim=xlim, ylim=ylim, main=main)#
		} else if(!add){#
			plot(d, col=col[1], type='l', main=main,				xlim=xlim, ylim=ylim)#
			abline(h=0)#
		}#
		if(histo[1] %in% c('hollow', 'faded') | add){#
			points(d, col=col[1], type='l',#
				lty=lty, lwd=lwd)#
		}#
	}#
}
par(mfrow=c(2,2))#
histPlot(tips$tip[tips$day == 'Tuesday'], hollow=TRUE, xlim=c(0, 30), lty=1)#
histPlot(tips$tip[tips$day == 'Friday'], hollow=TRUE, border='red', add=TRUE)#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
densityPlot(tips$tip, tips$day, col=c('black', 'red'))#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
data(run10)#
densityPlot(run10$time, histo='faded', breaks=15)#
densityPlot(run10$time, histo='hollow', breaks=30, fadingBorder='66', lty=1)
`densityPlot` <-#
function(x, fact=NULL, bw = "nrd0", histo=c('none', 'faded', 'hollow'), breaks='Sturges', fading='0E', fadingBorder='25', lty=NULL, lwd=1, col=c('black', 'red', 'blue'), key=NULL, add=FALSE, adjust = 1, kernel = c("gaussian", "epanechnikov", "rectangular","triangular", "biweight", "cosine", "optcosine"), weights = NULL, n = 512, from, to, na.rm = FALSE, xlim=NULL, ylim=NULL, main=''){#
	if(!is.null(fact)[1]){#
		d <- list()#
		fact <- as.character(fact)#
		if(is.null(key)[1]){#
			key <- unique(fact)#
		}#
		K <- length(key)#
		if(is.null(lty)[1]){#
			lty <- 1:K#
		}#
		if(is.null(lwd)[1]){#
			lwd <- rep(1,K)#
		}#
		xR <- NULL#
		yR <- NULL#
		for(i in 1:K){#
			d[[i]] <- density(x[fact == key[i]],#
				bw=bw, adjust=adjust, kernel=kernel,#
				weights=weights, n=n, from=from, to=to,#
				na.rm=na.rm)#
			xR <- range(c(xR, d[[i]]$x))#
			yR <- max(c(yR, max(d[[i]]$y)))#
		}#
		if(is.null(xlim)[1]){#
			xlim <- xR#
		}#
		if(is.null(ylim)[1]){#
			ylim <- c(0,yR)#
		}#
		if(add){#
			for(i in 1:K){#
				densityPlot(x[fact==key[i]], add=TRUE,#
					col=col[i], lty=lty[i], lwd=lwd[i],#
					xlim=xlim, ylim=ylim)#
			}#
		} else {#
			densityPlot(x[fact==key[1]], add=FALSE,#
				col=col[1], lty=lty[1], lwd=lwd[1],#
				xlim=xlim, ylim=ylim)#
			if(K > 1){#
				for(i in 2:K){#
					densityPlot(x[fact==key[i]], add=TRUE,#
						col=col[i], lty=lty[i], lwd=lwd[i])#
				}#
			}#
		}#
	} else {#
		K <- 1#
		d <- density(x, bw=bw, adjust=adjust, kernel=kernel,#
			weights=weights, n=n, from=from, to=to, na.rm=na.rm)#
		xR <- range(d$x)#
		yR <- max(d$y)#
		if(histo[1] %in% c('hollow', 'faded')){#
			H <- hist(x, breaks=breaks, plot=FALSE)#
			xR <- range(c(xR, H$breaks))#
			yR <- max(c(yR, max(H$density)))#
		}#
		if(is.null(xlim)[1]){#
			xlim <- xR#
		}#
		if(is.null(ylim)[1]){#
			ylim <- c(0,yR)#
		}#
		if(histo[1]=='hollow'){#
			histPlot(x, col=fadeColor(col[1],fading),#
				border=fadeColor(col[1],fadingBorder),#
				breaks=breaks, probability=TRUE,#
				add=add, xlim=xlim, ylim=ylim, main=main,#
				hollow=TRUE)#
		} else if(histo[1]=='faded'){#
			histPlot(x, col=fadeColor(col[1],fading),#
				border=fadeColor(col[1],fadingBorder),#
				breaks=breaks, probability=TRUE,#
				add=add, xlim=xlim, ylim=ylim, main=main)#
		} else if(!add){#
			plot(d, col=col[1], type='l', main=main,				xlim=xlim, ylim=ylim)#
			abline(h=0)#
		}#
		if(histo[1] %in% c('hollow', 'faded') | add){#
			points(d, col=col[1], type='l',#
				lty=lty, lwd=lwd)#
		}#
	}#
}
par(mfrow=c(2,2))#
histPlot(tips$tip[tips$day == 'Tuesday'], hollow=TRUE, xlim=c(0, 30), lty=1)#
histPlot(tips$tip[tips$day == 'Friday'], hollow=TRUE, border='red', add=TRUE)#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
densityPlot(tips$tip, tips$day, col=c('black', 'red'))#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
data(run10)#
densityPlot(run10$time, histo='faded', breaks=15)#
densityPlot(run10$time, histo='hollow', breaks=30, fadingBorder='66', lty=1)
par(mfrow=c(2,2))#
histPlot(tips$tip[tips$day == 'Tuesday'], hollow=TRUE, xlim=c(0, 30), lty=1, main='Tips by day')#
histPlot(tips$tip[tips$day == 'Friday'], hollow=TRUE, border='red', add=TRUE, main='Tips by day')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
densityPlot(tips$tip, tips$day, col=c('black', 'red'), main='Tips by day')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
data(run10)#
densityPlot(run10$time, histo='faded', breaks=15, main='Run time')#
densityPlot(run10$time, histo='hollow', breaks=30, fadingBorder='66', lty=1, main='Run time')
`histPlot` <-#
function(x, col=fadeColor('black', '22'), border='black', breaks="default", probability=FALSE, hollow=FALSE, add=FALSE, lty=2, lwd=1, freqTable=FALSE, right=TRUE, axes=TRUE, xlab=NULL, ylab=NULL, xlim=NULL, ylim=NULL, ...){#
	if(breaks[1] == 'default'){#
		breaks <- 'Sturges'#
	}#
	if(freqTable){#
		nObs <- sum(x[,2])#
		xR   <- range(x[,1])#
		xR   <- xR + c(-1,1)*diff(xR)/10^5#
		H    <- list()#
		if(is.character(breaks)[1]){#
			breaks <- 10#
		}#
		if(length(breaks) == 1){#
			H$breaks <- pretty(xR, n=breaks, min.n=1)#
		} else {#
			H$breaks <- breaks#
		}#
		H$mids <- H$breaks[-1] - diff(H$breaks)/2#
		H$counts <- rep(0, length(H$mids))#
		for(i in 1:length(H$counts)){#
			if(right){#
				temp <- which(x[,1] <= H$breaks[i+1] & x[,1] > H$breaks[i])#
			} else {#
				temp <- which(x[,1] < H$breaks[i+1] & x[,1] >= H$breaks[i])#
			}#
			H$counts[i] <- sum(x[temp,2])#
		}#
		H$density <- (H$counts/sum(H$counts))/diff(H$breaks)#
	} else {#
		if(length(breaks) > 1 && is.numeric(breaks)[1]){#
			H <- hist(x, breaks=breaks, plot=FALSE, right=right, include.lowest=FALSE)#
		} else {#
			H <- hist(x, breaks=breaks, plot=FALSE, right=right)#
		}#
	}#
	br <- H$breaks#
	mi <- H$mids#
	y <- H$counts#
	if(probability){#
		y <- H$density#
	}#
	if(is.null(ylab)){#
		ylab <- 'frequency'#
		if(probability){#
			ylab <- 'density'#
		}#
	}#
	if(is.null(xlab)){#
		xlab <- H$xname#
	}#
	if(is.null(xlim)){#
		xlim <- range(br)#
	}#
	if(is.null(ylim)){#
		ylim=c(0,max(y))#
	}#
	if(!add){#
		plot(x, xlim=xlim, ylim=ylim, type='n', axes=FALSE, ylab=ylab, xlab=xlab, main=main, ...)#
		abline(h=0)#
		if(axes){#
			axis(1)#
			axis(2)#
		}#
	}#
	if(hollow){#
		n  <- length(H$breaks)#
		br <- c(br[1], br)#
		y  <- c(0, y, 0)#
		points(br, y, type='s', col=border, lty=lty, lwd=lwd)#
	} else {#
		miL <- length(mi)#
		for(i in 1:miL){#
			rect(br[i], 0, br[i+1], y[i],#
				border='#ffffff00', col=col)#
			lines(rep(br[i],2), c(0,y[i]), col=border)#
			lines(br[i:(i+1)], rep(y[i],2), col=border)#
			if(i > 1){#
				if(y[i] < y[i-1]){#
					lines(rep(br[i],2), y[(i-1):i], col=border)#
				}#
			}#
		}#
		lines(rep(br[miL+1],2), c(0,y[miL]), col=border)#
	}#
}
par(mfrow=c(2,2))#
histPlot(tips$tip[tips$day == 'Tuesday'], hollow=TRUE, xlim=c(0, 30), lty=1, main='Tips by day')#
histPlot(tips$tip[tips$day == 'Friday'], hollow=TRUE, border='red', add=TRUE, main='Tips by day')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
densityPlot(tips$tip, tips$day, col=c('black', 'red'), main='Tips by day')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
data(run10)#
densityPlot(run10$time, histo='faded', breaks=15, main='Run time')#
densityPlot(run10$time, histo='hollow', breaks=30, fadingBorder='66', lty=1, main='Run time')
`histPlot` <-#
function(x, col=fadeColor('black', '22'), border='black', breaks="default", probability=FALSE, hollow=FALSE, add=FALSE, lty=2, lwd=1, freqTable=FALSE, right=TRUE, axes=TRUE, xlab=NULL, ylab=NULL, xlim=NULL, ylim=NULL, ...){#
	if(breaks[1] == 'default'){#
		breaks <- 'Sturges'#
	}#
	if(freqTable){#
		nObs <- sum(x[,2])#
		xR   <- range(x[,1])#
		xR   <- xR + c(-1,1)*diff(xR)/10^5#
		H    <- list()#
		if(is.character(breaks)[1]){#
			breaks <- 10#
		}#
		if(length(breaks) == 1){#
			H$breaks <- pretty(xR, n=breaks, min.n=1)#
		} else {#
			H$breaks <- breaks#
		}#
		H$mids <- H$breaks[-1] - diff(H$breaks)/2#
		H$counts <- rep(0, length(H$mids))#
		for(i in 1:length(H$counts)){#
			if(right){#
				temp <- which(x[,1] <= H$breaks[i+1] & x[,1] > H$breaks[i])#
			} else {#
				temp <- which(x[,1] < H$breaks[i+1] & x[,1] >= H$breaks[i])#
			}#
			H$counts[i] <- sum(x[temp,2])#
		}#
		H$density <- (H$counts/sum(H$counts))/diff(H$breaks)#
	} else {#
		if(length(breaks) > 1 && is.numeric(breaks)[1]){#
			H <- hist(x, breaks=breaks, plot=FALSE, right=right, include.lowest=FALSE)#
		} else {#
			H <- hist(x, breaks=breaks, plot=FALSE, right=right)#
		}#
	}#
	br <- H$breaks#
	mi <- H$mids#
	y <- H$counts#
	if(probability){#
		y <- H$density#
	}#
	if(is.null(ylab)){#
		ylab <- 'frequency'#
		if(probability){#
			ylab <- 'density'#
		}#
	}#
	if(is.null(xlab)){#
		xlab <- H$xname#
	}#
	if(is.null(xlim)){#
		xlim <- range(br)#
	}#
	if(is.null(ylim)){#
		ylim=c(0,max(y))#
	}#
	if(!add){#
		plot(x, xlim=xlim, ylim=ylim, type='n', axes=FALSE, ylab=ylab, xlab=xlab, ...)#
		abline(h=0)#
		if(axes){#
			axis(1)#
			axis(2)#
		}#
	}#
	if(hollow){#
		n  <- length(H$breaks)#
		br <- c(br[1], br)#
		y  <- c(0, y, 0)#
		points(br, y, type='s', col=border, lty=lty, lwd=lwd)#
	} else {#
		miL <- length(mi)#
		for(i in 1:miL){#
			rect(br[i], 0, br[i+1], y[i],#
				border='#ffffff00', col=col)#
			lines(rep(br[i],2), c(0,y[i]), col=border)#
			lines(br[i:(i+1)], rep(y[i],2), col=border)#
			if(i > 1){#
				if(y[i] < y[i-1]){#
					lines(rep(br[i],2), y[(i-1):i], col=border)#
				}#
			}#
		}#
		lines(rep(br[miL+1],2), c(0,y[miL]), col=border)#
	}#
}
par(mfrow=c(2,2))#
histPlot(tips$tip[tips$day == 'Tuesday'], hollow=TRUE, xlim=c(0, 30), lty=1, main='Tips by day')#
histPlot(tips$tip[tips$day == 'Friday'], hollow=TRUE, border='red', add=TRUE, main='Tips by day')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
densityPlot(tips$tip, tips$day, col=c('black', 'red'), main='Tips by day')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
data(run10)#
densityPlot(run10$time, histo='faded', breaks=15, main='Run time')#
densityPlot(run10$time, histo='hollow', breaks=30, fadingBorder='66', lty=1, main='Run time')
`densityPlot` <-#
function(x, fact=NULL, bw = "nrd0", histo=c('none', 'faded', 'hollow'), breaks='Sturges', fading='0E', fadingBorder='25', lty=NULL, lwd=1, col=c('black', 'red', 'blue'), key=NULL, add=FALSE, adjust = 1, kernel = c("gaussian", "epanechnikov", "rectangular","triangular", "biweight", "cosine", "optcosine"), weights = NULL, n = 512, from, to, na.rm = FALSE, xlim=NULL, ylim=NULL, main=''){#
	if(!is.null(fact)[1]){#
		d <- list()#
		fact <- as.character(fact)#
		if(is.null(key)[1]){#
			key <- unique(fact)#
		}#
		K <- length(key)#
		if(is.null(lty)[1]){#
			lty <- 1:K#
		}#
		if(is.null(lwd)[1]){#
			lwd <- rep(1,K)#
		}#
		xR <- NULL#
		yR <- NULL#
		for(i in 1:K){#
			d[[i]] <- density(x[fact == key[i]],#
				bw=bw, adjust=adjust, kernel=kernel,#
				weights=weights, n=n, from=from, to=to,#
				na.rm=na.rm)#
			xR <- range(c(xR, d[[i]]$x))#
			yR <- max(c(yR, max(d[[i]]$y)))#
		}#
		if(is.null(xlim)[1]){#
			xlim <- xR#
		}#
		if(is.null(ylim)[1]){#
			ylim <- c(0,yR)#
		}#
		if(add){#
			for(i in 1:K){#
				densityPlot(x[fact==key[i]], add=TRUE,#
					col=col[i], lty=lty[i], lwd=lwd[i],#
					xlim=xlim, ylim=ylim)#
			}#
		} else {#
			densityPlot(x[fact==key[1]], add=FALSE,#
				col=col[1], lty=lty[1], lwd=lwd[1],#
				xlim=xlim, ylim=ylim, main=main)#
			if(K > 1){#
				for(i in 2:K){#
					densityPlot(x[fact==key[i]], add=TRUE,#
						col=col[i], lty=lty[i], lwd=lwd[i])#
				}#
			}#
		}#
	} else {#
		K <- 1#
		d <- density(x, bw=bw, adjust=adjust, kernel=kernel,#
			weights=weights, n=n, from=from, to=to, na.rm=na.rm)#
		xR <- range(d$x)#
		yR <- max(d$y)#
		if(histo[1] %in% c('hollow', 'faded')){#
			H <- hist(x, breaks=breaks, plot=FALSE)#
			xR <- range(c(xR, H$breaks))#
			yR <- max(c(yR, max(H$density)))#
		}#
		if(is.null(xlim)[1]){#
			xlim <- xR#
		}#
		if(is.null(ylim)[1]){#
			ylim <- c(0,yR)#
		}#
		if(histo[1]=='hollow'){#
			histPlot(x, col=fadeColor(col[1],fading),#
				border=fadeColor(col[1],fadingBorder),#
				breaks=breaks, probability=TRUE,#
				add=add, xlim=xlim, ylim=ylim, main=main,#
				hollow=TRUE)#
		} else if(histo[1]=='faded'){#
			histPlot(x, col=fadeColor(col[1],fading),#
				border=fadeColor(col[1],fadingBorder),#
				breaks=breaks, probability=TRUE,#
				add=add, xlim=xlim, ylim=ylim, main=main)#
		} else if(!add){#
			plot(d, col=col[1], type='l', main=main,				xlim=xlim, ylim=ylim)#
			abline(h=0)#
		}#
		if(histo[1] %in% c('hollow', 'faded') | add){#
			points(d, col=col[1], type='l',#
				lty=lty, lwd=lwd)#
		}#
	}#
}
par(mfrow=c(2,2))#
histPlot(tips$tip[tips$day == 'Tuesday'], hollow=TRUE, xlim=c(0, 30), lty=1, main='Tips by day')#
histPlot(tips$tip[tips$day == 'Friday'], hollow=TRUE, border='red', add=TRUE, main='Tips by day')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
densityPlot(tips$tip, tips$day, col=c('black', 'red'), main='Tips by day')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
data(run10)#
densityPlot(run10$time, histo='faded', breaks=15, main='Run time')#
densityPlot(run10$time, histo='hollow', breaks=30, fadingBorder='66', lty=1, main='Run time')
`boxPlot` <-#
function(x, fact=NULL, horiz=FALSE, width=2/3, lwd=1, lcol='black', medianLwd=2, pch=20, pchCex=1.8, col=fadeColor('black', '44'), add=FALSE, key=NULL, axes=TRUE, xlab='', ylab='', xlim=NULL, ylim=NULL, ...){#
	if(!is.null(fact)[1]){#
		fact <- as.character(fact)#
	} else {#
		fact <- rep('', length(x))#
	}#
	if(is.null(key)[1]){#
		uFact <- sort(unique(fact))#
	} else {#
		uFact <- key#
	}#
	N <- length(uFact)#
	fiveNum <- matrix(NA, N, 5)#
	for(i in 1:N){#
		fiveNum[i,] <- fivenum(x[fact == uFact[i]])#
	}#
	iqrAdj <- 1.5*(fiveNum[,4] - fiveNum[,2])#
	below <- which(fiveNum[,1] < fiveNum[,2]-iqrAdj)#
	if(length(below) > 0){#
		for(i in 1:length(below)){#
			fiveNum[below[i],1] <- min(x[x > fiveNum[below[i],2]-iqrAdj[below[i]] & fact == uFact[i]])#
		}#
	}#
	above <- which(fiveNum[,5] > fiveNum[,4]+iqrAdj)#
	if(length(above) > 0){#
		for(i in 1:length(above)){#
			fiveNum[above[i],5] <- max(x[x < fiveNum[above[i],4]+iqrAdj[above[i]] & fact == uFact[i]])#
		}#
	}#
#	below <- fiveNum[,1] < fiveNum[,2]-iqrAdj#
#	fiveNum[below,1] <- fiveNum[below,2]-iqrAdj[below]#
#	above <- fiveNum[,5] > fiveNum[,4]+iqrAdj#
#	fiveNum[above,5] <- fiveNum[above,4]+iqrAdj[above]#
	w <- width/2#
	if(horiz){#
		if(is.null(ylim)){#
			yR <- c(1-2*w,N+2*w)#
		} else {#
			yR <- ylim#
		}#
		if(is.null(xlim)){#
			xR <- range(x)#
			xR <- xR + c(-1,1)*diff(xR)/30#
		} else {#
			xR <- xlim#
		}#
		if(is.logical(add[1])){#
			if(!add[1]){#
				plot(1:length(x),x,type='n',axes=FALSE, xlim=xR, xlab=xlab, ylab=ylab, ylim=yR, ...)#
			}#
			add <- 1:N#
		} #
		if(N == 1){#
			w <- w/1.3#
		}#
		for(i in 1:N){#
			bds <- add[i]+w*c(-1,1)#
			lines(rep(fiveNum[i,1],2), bds, col=lcol, lwd=lwd)#
			lines(fiveNum[i,1:2], c(add[i],add[i]), col=lcol, lwd=lwd)#
			rect(fiveNum[i,2], add[i]-w, fiveNum[i,4], add[i]+w, border=lcol, lwd=lwd)#
			lines(rep(fiveNum[i,3], 2), bds, col=lcol, lwd=medianLwd)#
			lines(fiveNum[i,4:5], c(add[i],add[i]), col=lcol, lwd=lwd)#
			lines(rep(fiveNum[i,5],2), bds, col=lcol, lwd=lwd)#
			if(i %in% above){#
				X <- x[fact == uFact[i] & x > fiveNum[i,5]]#
				points(X, rep(add[i], length(X)), pch=pch, col=col, cex=pchCex)#
			}#
			if(i %in% below){#
				X <- x[fact == uFact[i] & x < fiveNum[i,1]]#
				points(X, rep(add[i], length(X)), pch=pch, col=col, cex=pchCex)#
			}#
		}#
		if(axes){#
			if(N > 1){#
				axis(2, at=add, labels=uFact)#
			}#
			axis(1)#
			box()#
		}#
	} else {#
		if(is.null(ylim)){#
			yR <- range(x)#
			yR <- yR + c(-1,1)*diff(yR)/30#
		} else {#
			yR <- ylim#
		}#
		if(is.null(xlim)){#
			xR <- c(1-2*w,N+2*w)#
		} else {#
			xR <- xlim#
		}#
		if(is.logical(add[1])){#
			if(!add[1]){#
				plot(1:length(x),x,type='n',axes=FALSE, xlim=xR, xlab=xlab, ylab=ylab, ylim=yR, ...)#
			}#
			add <- 1:N#
		}#
		if(N == 1){#
			w <- w/1.3#
		}#
		for(i in 1:N){#
			bds <- add[i]+w*c(-1,1)#
			lines(bds, rep(fiveNum[i,1],2), col=lcol, lwd=lwd)#
			lines(c(add[i],add[i]), fiveNum[i,1:2], col=lcol, lwd=lwd)#
			rect(add[i]-w, fiveNum[i,2], add[i]+w, fiveNum[i,4], border=lcol, lwd=lwd)#
			lines(bds, rep(fiveNum[i,3], 2), col=lcol, lwd=medianLwd)#
			lines(c(add[i],add[i]), fiveNum[i,4:5], col=lcol, lwd=lwd)#
			lines(bds, rep(fiveNum[i,5],2), col=lcol, lwd=lwd)#
			if(i %in% above){#
				X <- x[fact == uFact[i] & x > fiveNum[i,5]]#
				points(rep(add[i], length(X)), X, pch=pch, col=col, cex=pchCex)#
			}#
			if(i %in% below){#
				X <- x[fact == uFact[i] & x < fiveNum[i,1]]#
				points(rep(add[i], length(X)), X, pch=pch, col=col, cex=pchCex)#
			}#
		}#
		if(axes){#
			if(N > 1){#
				axis(1, at=add, labels=uFact)#
			}#
			axis(2)#
			box()#
		}#
	}#
}
par(mfrow=1:2)#
#
#===> comparison 1 <===##
boxPlot(run10$time)#
boxplot(run10$time)
#===> comparison 2 <===##
boxPlot(run10$time, run10$gender, col=fadeColor('black', '22'))#
boxplot(run10$time ~ run10$gender)
#===> modifications using boxPlot <===##
par(mfrow=c(2,2))#
boxPlot(run10$time, run10$gender)#
boxPlot(run10$time, run10$gender, xlab='gender', ylab='run time (min)', col='#00000018')#
plot(0,0, xlab='gender', ylab='run time (min)', xlim=c(0,6), ylim=c(30, 180), axes=FALSE)#
boxPlot(run10$time, run10$gender, width=0.5, lwd=2, lcol=4, medianLwd=4, pch=1, pchCex=1, col=4, add=c(1,2,5), key=c('M','F','N'))#
plot(0,0, ylab='gender', xlab='run time (min)', xlim=c(30, 180), ylim=c(0, 3), axes=FALSE)#
boxPlot(run10$time, run10$gender, horiz=TRUE, xlab='run time (min)', ylab='gender', add=1:2, key=c('F','M'))
#===> adding a box <===##
par(mfrow=1:2)#
boxPlot(run10$time[run10$gender=='M'], xlim=c(0,3))#
boxPlot(run10$time[run10$gender=='F'], add=2, axes=FALSE)#
axis(1, at=1:2, labels=c('M', 'F'))#
boxPlot(run10$time[run10$gender=='M'], ylim=c(0,3), horiz=TRUE)#
boxPlot(run10$time[run10$gender=='F'], add=2, horiz=TRUE, axes=FALSE)#
axis(2, at=1:2, labels=c('M', 'F'))
#===> modifications using boxPlot <===##
par(mfrow=c(2,2))#
boxPlot(run10$time, run10$gender)#
boxPlot(run10$time, run10$gender, xlab='gender', ylab='run time (min)', col=fadeColor('black', '18'))#
plot(0,0, xlab='gender', ylab='run time (min)', xlim=c(0,6), ylim=c(30, 180), axes=FALSE)#
boxPlot(run10$time, run10$gender, width=0.5, lwd=2, lcol=4, medianLwd=4, pch=1, pchCex=1, col=4, add=c(1,2,5), key=c('M','F','N'))#
plot(0,0, ylab='gender', xlab='run time (min)', xlim=c(30, 180), ylim=c(0, 3), axes=FALSE)#
boxPlot(run10$time, run10$gender, horiz=TRUE, xlab='run time (min)', ylab='gender', add=1:2, key=c('F','M'))#
# 'key' can be used to restrict to only the#
# desired groups
`dotPlot` <-#
function(x, fact=NULL, vertical=FALSE, at=1, key=NULL, pch=20, col=fadeColor('black', '66'), cex=1, add=FALSE, axes=TRUE, xlim=NULL, ylim=NULL, ...){#
	skipOut <- FALSE#
	if(!is.null(fact[1])){#
		if(!is.null(key[1])){#
			uFact <- key#
		} else {#
			uFact <- unique(fact)#
		}#
		n <- length(uFact)#
		if(length(at) == 1){#
			at <- 1:n#
		}#
		dataR <- range(x)#
		atR <- range(at)#
		if(!vertical){#
			if(is.null(xlim[1])){#
				xlim <- dataR#
			}#
			if(is.null(ylim[1])){#
				ylim <- atR + c(-1,1)*diff(atR)/7#
			}#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- atR + c(-1,1)*diff(atR)/7#
			}#
			if(is.null(ylim[1])){#
				ylim <- dataR#
			}#
		}#
		if(length(pch) == 1){#
			pch <- rep(pch, length(at))#
		}#
		if(length(col) == 1){#
			col <- rep(col, length(at))#
		}#
		if(length(cex) == 1){#
			cex <- rep(cex, length(at))#
		}#
		dotPlot(x[fact == uFact[1]], vertical=vertical, at=at[1], axes=axes, add=add, pch=pch[1], col=col[1], cex=cex[1], xlim=xlim, ylim=ylim, ...)#
		for(i in 2:n){#
			dotPlot(x[fact == uFact[i]], vertical=vertical, at=at[i], add=TRUE, pch=pch[i], col=col[i], cex=cex[i], axes=FALSE)#
		}#
		if(axes){#
			if(vertical){#
				axis(1, at=at, labels=uFact)#
			} else {#
				axis(2, at=at, labels=uFact)#
			}#
		}#
		skipOut=TRUE#
	}#
	y <- rep(at[1], length(x))#
	if(vertical & !skipOut){#
		if(add){#
			points(y,x, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- at[1]+c(-1,1)#
			}#
			if(is.null(ylim[1])){#
				ylim <- range(x)#
			}#
			plot(y,x,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	} else if(!skipOut){#
		if(add){#
			points(x,y, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(ylim[1])){#
				ylim <- at[1]+c(-1,1)#
			}#
			if(is.null(xlim[1])){#
				xlim <- range(x)#
			}#
			plot(x,y,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	}#
	if(axes){#
		axis(vertical+1)#
	}#
}
layout(matrix(1:2,1), heights=c(2.5,1.5))#
par(las=1)#
dotPlot(run10$time[run10$gender=='M'], run10$div[run10$gender=='M'], col='#00000011')#
# disorganized levels in the above plot, which we could#
# organize with key. an example of organizing the levels...#
dotPlot(run10$time[run10$gender=='M'], run10$div[run10$gender=='M'], col='#00000011', key=c('20-24', '25-29', '30-34', '35-39')) # just looking at male runners who are 20 to 39#
par(las=0, mfrow=c(1,1))
layout(matrix(1:2,2), heights=c(2.5,1.5))#
par(las=1)#
dotPlot(run10$time[run10$gender=='M'], run10$div[run10$gender=='M'], col='#00000011')#
# disorganized levels in the above plot, which we could#
# organize with key. an example of organizing the levels...#
dotPlot(run10$time[run10$gender=='M'], run10$div[run10$gender=='M'], col='#00000011', key=c('20-24', '25-29', '30-34', '35-39')) # just looking at male runners who are 20 to 39#
par(las=0, mfrow=c(1,1))
dotPlot(marioKart$totalPr, marioKart$cond, ylim=c(0.5,2.5), xlim=c(25, 80)) # the ylim is low enough that we do not observe the outliers#
boxPlot(marioKart$totalPr, marioKart$cond, add=1:2+0.1, key=c('new', 'used'), horiz=TRUE, axes=FALSE)
#
#===> example 2 <===##
data(run10)#
layout(matrix(1:2,2), heights=c(2.5,1.5))#
par(las=1)#
dotPlot(run10$time[run10$gender=='M'], run10$div[run10$gender=='M'], col=fadeColor('black', '11'))#
# disorganized levels in the above plot, which we could#
# organize with key. an example of organizing the levels...#
dotPlot(run10$time[run10$gender=='M'], run10$div[run10$gender=='M'], col=fadeColor('black', '11'), key=c('20-24', '25-29', '30-34', '35-39')) # just looking at male runners who are 20 to 39#
par(las=0, mfrow=c(1,1))
layout(matrix(1:2,2), heights=c(2.7,1.5))#
par(las=1)#
dotPlot(run10$time[run10$gender=='M'], run10$div[run10$gender=='M'], col=fadeColor('black', '11'))#
# disorganized levels in the above plot, which we could#
# organize with key. an example of organizing the levels...#
dotPlot(run10$time[run10$gender=='M'], run10$div[run10$gender=='M'], col=fadeColor('black', '11'), key=c('20-24', '25-29', '30-34', '35-39')) # just looking at male runners who are 20 to 39#
par(las=0, mfrow=c(1,1))
dotPlot(marioKart$totalPr, marioKart$cond, ylim=c(0.5,2.5), xlim=c(25, 80)) # the ylim is low enough that we do not observe the outliers#
boxPlot(marioKart$totalPr, marioKart$cond, add=1:2+0.1, key=c('new', 'used'), horiz=TRUE, axes=FALSE)
par(mfrow=c(2,2))#
histPlot(run10$time, col=fadeColor('blue', '22'), border='blue')#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='#885522')#
legend('topleft', col=c('#225588', '#885522'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)))
par(mfrow=c(2,2))#
histPlot(run10$time, col=fadeColor('blue', '22'), border='blue')#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)))
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('blue', '22'), border='blue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)))
par(mfrow=1:2)#
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), pch=20, col=2, cex=2, main='using regular colors')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col=4, pch=20, cex=2)#
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), col=fadeColor(2, '22'), pch=20, cex=2, main='fading the colors first')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col=fadeColor(4, '22'), pch=20, cex=2)
#===> color names <===##
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), pch=20, col='red', cex=2, main='using regular colors')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col='blue', pch=20, cex=2)#
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), col=fadeColor('red', '22'), pch=20, cex=2, main='fading the colors first')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col=fadeColor('blue', '22'), pch=20, cex=2)
#===> hexadecimal <===##
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), pch=20, col='#FF0000', cex=2, main='using regular colors')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col='#0000FF', pch=20, cex=2)#
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), col=fadeColor('#FF0000', '22'), pch=20, cex=2, main='fading the colors first')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col=fadeColor('#0000FF', '22'), pch=20, cex=2)
#===> alternative: rgb function <===##
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), pch=20, col=rgb(1,0,0), cex=2, main='using regular colors')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col=rgb(0,0,1), pch=20, cex=2)#
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), col=rgb(1,0,0,1/8), pch=20, cex=2, main='fading the colors first')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col=rgb(0,0,1,1/8), pch=20, cex=2)
rgb(0,0,1,1/8)
34/256
#
#===> adding a box <===##
par(mfrow=1:2)#
boxPlot(run10$time[run10$gender=='M'], xlim=c(0,3))#
boxPlot(run10$time[run10$gender=='F'], add=2, axes=FALSE)#
axis(1, at=1:2, labels=c('M', 'F'))#
boxPlot(run10$time[run10$gender=='M'], ylim=c(0,3), horiz=TRUE)#
boxPlot(run10$time[run10$gender=='F'], add=2, horiz=TRUE, axes=FALSE)#
axis(2, at=1:2, labels=c('M', 'F'))
#===> comparison 1 <===##
boxPlot(run10$time)#
boxplot(run10$time)
#===> modifications using boxPlot <===##
par(mfrow=c(2,2))#
boxPlot(run10$time, run10$gender)#
boxPlot(run10$time, run10$gender, xlab='gender', ylab='run time (min)', col=fadeColor('black', '18'))#
plot(0,0, xlab='gender', ylab='run time (min)', xlim=c(0,6), ylim=c(30, 180), axes=FALSE)#
boxPlot(run10$time, run10$gender, width=0.5, lwd=2, lcol=4, medianLwd=4, pch=1, pchCex=1, col=4, add=c(1,2,5), key=c('M','F','N'))#
plot(0,0, ylab='gender', xlab='run time (min)', xlim=c(30, 180), ylim=c(0, 3), axes=FALSE)#
boxPlot(run10$time, run10$gender, horiz=TRUE, xlab='run time (min)', ylab='gender', add=1:2, key=c('F','M'))
par(mfrow=c(1,1))#
boxPlot(run10$time, run10$gender, key=c('F', 'M'))#
dotPlot(run10$time, run10$gender, key=c('F', 'M'))
#===> combine boxPlot and dotPlot <===##
par(mfrow=c(1,1))#
boxPlot(run10$time, run10$gender, key=c('F', 'M'))#
dotPlot(run10$time, run10$gender, key=c('F', 'M'), add=1:2+0.05, vertical=TRUE)
par(mfrow=c(1,1))#
boxPlot(tips$tip, tips$day)#
dotPlot(tips$tip, tips$day, add=1:2+0.05, vertical=TRUE)
`dotPlot` <-#
function(x, fact=NULL, vertical=FALSE, at=1, key=NULL, pch=20, col=fadeColor('black', '66'), cex=1, add=FALSE, axes=TRUE, xlim=NULL, ylim=NULL, ...){#
	skipOut <- FALSE#
	if(!is.null(fact[1])){#
		if(!is.null(key[1])){#
			uFact <- key#
		} else {#
			uFact <- unique(fact)#
		}#
		n <- length(uFact)#
		if(length(at) == 1){#
			at <- 1:n#
		}#
		dataR <- range(x)#
		atR <- range(at)#
		if(!vertical){#
			if(is.null(xlim[1])){#
				xlim <- dataR#
			}#
			if(is.null(ylim[1])){#
				ylim <- atR + c(-1,1)*diff(atR)/7#
			}#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- atR + c(-1,1)*diff(atR)/7#
			}#
			if(is.null(ylim[1])){#
				ylim <- dataR#
			}#
		}#
		if(length(pch) == 1){#
			pch <- rep(pch, length(at))#
		}#
		if(length(col) == 1){#
			col <- rep(col, length(at))#
		}#
		if(length(cex) == 1){#
			cex <- rep(cex, length(at))#
		}#
		dotPlot(x[fact == uFact[1]], vertical=vertical, at=at[1], axes=axes, add=add, pch=pch[1], col=col[1], cex=cex[1], xlim=xlim, ylim=ylim, ...)#
		for(i in 2:n){#
			dotPlot(x[fact == uFact[i]], vertical=vertical, at=at[i], add=TRUE, pch=pch[i], col=col[i], cex=cex[i], axes=FALSE)#
		}#
		if(axes){#
			if(vertical){#
				axis(1, at=at, labels=uFact)#
			} else {#
				axis(2, at=at, labels=uFact)#
			}#
		}#
		skipOut=TRUE#
	}#
	y <- rep(at[1], length(x))#
	if(vertical & !skipOut){#
		if(add){#
			points(y,x, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- at[1]+c(-1,1)#
			}#
			if(is.null(ylim[1])){#
				ylim <- range(x)#
			}#
			plot(y,x,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	} else if(!skipOut){#
		if(add){#
			points(x,y, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(ylim[1])){#
				ylim <- at[1]+c(-1,1)#
			}#
			if(is.null(xlim[1])){#
				xlim <- range(x)#
			}#
			plot(x,y,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	}#
	if(axes & (add == FALSE)){#
		axis(vertical+1)#
	}#
}
par(mfrow=c(1,1))#
boxPlot(tips$tip, tips$day)#
dotPlot(tips$tip, tips$day, add=1:2+0.05, vertical=TRUE)
`dotPlot` <-#
function(x, fact=NULL, vertical=FALSE, at=1, key=NULL, pch=20, col=fadeColor('black', '66'), cex=1, add=FALSE, axes=TRUE, xlim=NULL, ylim=NULL, ...){#
	skipOut <- FALSE#
	if(!is.null(fact[1])){#
		if(!is.null(key[1])){#
			uFact <- key#
		} else {#
			uFact <- unique(fact)#
		}#
		n <- length(uFact)#
		if(length(at) == 1){#
			at <- 1:n#
		}#
		dataR <- range(x)#
		atR <- range(at)#
		if(!vertical){#
			if(is.null(xlim[1])){#
				xlim <- dataR#
			}#
			if(is.null(ylim[1])){#
				ylim <- atR + c(-1,1)*diff(atR)/7#
			}#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- atR + c(-1,1)*diff(atR)/7#
			}#
			if(is.null(ylim[1])){#
				ylim <- dataR#
			}#
		}#
		if(length(pch) == 1){#
			pch <- rep(pch, length(at))#
		}#
		if(length(col) == 1){#
			col <- rep(col, length(at))#
		}#
		if(length(cex) == 1){#
			cex <- rep(cex, length(at))#
		}#
		dotPlot(x[fact == uFact[1]], vertical=vertical, at=at[1], axes=axes, add=add, pch=pch[1], col=col[1], cex=cex[1], xlim=xlim, ylim=ylim, ...)#
		for(i in 2:n){#
			dotPlot(x[fact == uFact[i]], vertical=vertical, at=at[i], add=TRUE, pch=pch[i], col=col[i], cex=cex[i], axes=FALSE)#
		}#
		if(axes){#
			if(vertical){#
				axis(1, at=at, labels=uFact)#
			} else {#
				axis(2, at=at, labels=uFact)#
			}#
		}#
		skipOut=TRUE#
	}#
	y <- rep(at[1], length(x))#
	if(vertical & !skipOut){#
		if(add){#
			points(y,x, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- at[1]+c(-1,1)#
			}#
			if(is.null(ylim[1])){#
				ylim <- range(x)#
			}#
			plot(y,x,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	} else if(!skipOut){#
		if(add){#
			points(x,y, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(ylim[1])){#
				ylim <- at[1]+c(-1,1)#
			}#
			if(is.null(xlim[1])){#
				xlim <- range(x)#
			}#
			plot(x,y,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	}#
	if(axes){#
		axis(vertical+1)#
	}#
}
par(mfrow=c(1,1))#
boxPlot(tips$tip, tips$day)#
dotPlot(tips$tip, tips$day, at=1:2+0.05, vertical=TRUE)
par(mfrow=c(1,1))#
boxPlot(tips$tip, tips$day)#
dotPlot(tips$tip, tips$day, add=TRUE, at=1:2+0.05, vertical=TRUE)
par(mfrow=c(1,1))#
boxPlot(tips$tip, tips$day, key=c('Tuesday', 'Friday'))#
dotPlot(tips$tip, tips$day, add=TRUE, at=1:2+0.05, key=c('Tuesday', 'Friday'), vertical=TRUE)
par(mfrow=c(1,1))#
boxPlot(tips$tip, tips$day, horiz=TRUE, key=c('Tuesday', 'Friday'))#
dotPlot(tips$tip, tips$day, add=TRUE, at=1:2+0.05, key=c('Tuesday', 'Friday'))
`dotPlot` <-#
function(x, fact=NULL, vertical=FALSE, at=1, key=NULL, pch=20, col=fadeColor('black', '66'), cex=1, add=FALSE, axes=TRUE, xlim=NULL, ylim=NULL, ...){#
	skipOut <- FALSE#
	if(!is.null(fact[1])){#
		if(!is.null(key[1])){#
			uFact <- key#
		} else {#
			uFact <- unique(fact)#
		}#
		n <- length(uFact)#
		if(length(at) == 1){#
			at <- 1:n#
		}#
		dataR <- range(x)#
		atR <- range(at)#
		if(!vertical){#
			if(is.null(xlim[1])){#
				xlim <- dataR#
			}#
			if(is.null(ylim[1])){#
				ylim <- atR + c(-1,1)*diff(atR)/7#
			}#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- atR + c(-1,1)*diff(atR)/7#
			}#
			if(is.null(ylim[1])){#
				ylim <- dataR#
			}#
		}#
		if(length(pch) == 1){#
			pch <- rep(pch, length(at))#
		}#
		if(length(col) == 1){#
			col <- rep(col, length(at))#
		}#
		if(length(cex) == 1){#
			cex <- rep(cex, length(at))#
		}#
		dotPlot(x[fact == uFact[1]], vertical=vertical, at=at[1], axes=axes, add=add, pch=pch[1], col=col[1], cex=cex[1], xlim=xlim, ylim=ylim, ...)#
		for(i in 2:n){#
			dotPlot(x[fact == uFact[i]], vertical=vertical, at=at[i], add=TRUE, pch=pch[i], col=col[i], cex=cex[i], axes=FALSE)#
		}#
		if(axes){#
			if(vertical){#
				axis(1, at=at, labels=uFact)#
			} else {#
				axis(2, at=at, labels=uFact)#
			}#
		}#
		skipOut=TRUE#
	}#
	y <- rep(at[1], length(x))#
	if(vertical & !skipOut){#
		if(add){#
			points(y,x, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- at[1]+c(-1,1)#
			}#
			if(is.null(ylim[1])){#
				ylim <- range(x)#
			}#
			plot(y,x,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	} else if(!skipOut){#
		if(add){#
			points(x,y, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(ylim[1])){#
				ylim <- at[1]+c(-1,1)#
			}#
			if(is.null(xlim[1])){#
				xlim <- range(x)#
			}#
			plot(x,y,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	}#
	if(axes & !add){#
		axis(vertical+1)#
	}#
}
par(mfrow=c(1,1))#
boxPlot(tips$tip, tips$day, horiz=TRUE, key=c('Tuesday', 'Friday'))#
dotPlot(tips$tip, tips$day, add=TRUE, at=1:2+0.05, key=c('Tuesday', 'Friday'))
`dotPlot` <-#
function(x, fact=NULL, vertical=FALSE, at=1, key=NULL, pch=20, col=fadeColor('black', '66'), cex=1, add=FALSE, axes=TRUE, xlim=NULL, ylim=NULL, ...){#
	skipOut <- FALSE#
	if(!is.null(fact[1])){#
		if(!is.null(key[1])){#
			uFact <- key#
		} else {#
			uFact <- unique(fact)#
		}#
		n <- length(uFact)#
		if(length(at) == 1){#
			at <- 1:n#
		}#
		dataR <- range(x)#
		atR <- range(at)#
		if(!vertical){#
			if(is.null(xlim[1])){#
				xlim <- dataR#
			}#
			if(is.null(ylim[1])){#
				ylim <- atR + c(-1,1)*diff(atR)/7#
			}#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- atR + c(-1,1)*diff(atR)/7#
			}#
			if(is.null(ylim[1])){#
				ylim <- dataR#
			}#
		}#
		if(length(pch) == 1){#
			pch <- rep(pch, length(at))#
		}#
		if(length(col) == 1){#
			col <- rep(col, length(at))#
		}#
		if(length(cex) == 1){#
			cex <- rep(cex, length(at))#
		}#
		dotPlot(x[fact == uFact[1]], vertical=vertical, at=at[1], axes=axes, add=add, pch=pch[1], col=col[1], cex=cex[1], xlim=xlim, ylim=ylim, ...)#
		for(i in 2:n){#
			dotPlot(x[fact == uFact[i]], vertical=vertical, at=at[i], add=TRUE, pch=pch[i], col=col[i], cex=cex[i], axes=FALSE)#
		}#
		if(axes & !add){#
			if(vertical){#
				axis(1, at=at, labels=uFact)#
			} else {#
				axis(2, at=at, labels=uFact)#
			}#
		}#
		skipOut=TRUE#
	}#
	y <- rep(at[1], length(x))#
	if(vertical & !skipOut){#
		if(add){#
			points(y,x, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- at[1]+c(-1,1)#
			}#
			if(is.null(ylim[1])){#
				ylim <- range(x)#
			}#
			plot(y,x,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	} else if(!skipOut){#
		if(add){#
			points(x,y, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(ylim[1])){#
				ylim <- at[1]+c(-1,1)#
			}#
			if(is.null(xlim[1])){#
				xlim <- range(x)#
			}#
			plot(x,y,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	}#
	if(axes){#
		axis(vertical+1)#
	}#
}
par(mfrow=c(1,1))#
boxPlot(tips$tip, tips$day, horiz=TRUE, key=c('Tuesday', 'Friday'))#
dotPlot(tips$tip, tips$day, add=TRUE, at=1:2+0.05, key=c('Tuesday', 'Friday'))
`dotPlot` <-#
function(x, fact=NULL, vertical=FALSE, at=1, key=NULL, pch=20, col=fadeColor('black', '66'), cex=1, add=FALSE, axes=TRUE, xlim=NULL, ylim=NULL, ...){#
	skipOut <- FALSE#
	if(!is.null(fact[1])){#
		if(!is.null(key[1])){#
			uFact <- key#
		} else {#
			uFact <- unique(fact)#
		}#
		n <- length(uFact)#
		if(length(at) == 1){#
			at <- 1:n#
		}#
		dataR <- range(x)#
		atR <- range(at)#
		if(!vertical){#
			if(is.null(xlim[1])){#
				xlim <- dataR#
			}#
			if(is.null(ylim[1])){#
				ylim <- atR + c(-1,1)*diff(atR)/7#
			}#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- atR + c(-1,1)*diff(atR)/7#
			}#
			if(is.null(ylim[1])){#
				ylim <- dataR#
			}#
		}#
		if(length(pch) == 1){#
			pch <- rep(pch, length(at))#
		}#
		if(length(col) == 1){#
			col <- rep(col, length(at))#
		}#
		if(length(cex) == 1){#
			cex <- rep(cex, length(at))#
		}#
		dotPlot(x[fact == uFact[1]], vertical=vertical, at=at[1], axes=axes, add=add, pch=pch[1], col=col[1], cex=cex[1], xlim=xlim, ylim=ylim, ...)#
		for(i in 2:n){#
			dotPlot(x[fact == uFact[i]], vertical=vertical, at=at[i], add=TRUE, pch=pch[i], col=col[i], cex=cex[i], axes=FALSE)#
		}#
		if(axes & !add){#
			if(vertical){#
				axis(1, at=at, labels=uFact)#
			} else {#
				axis(2, at=at, labels=uFact)#
			}#
		}#
		skipOut=TRUE#
	}#
	y <- rep(at[1], length(x))#
	if(vertical & !skipOut){#
		if(add){#
			points(y,x, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- at[1]+c(-1,1)#
			}#
			if(is.null(ylim[1])){#
				ylim <- range(x)#
			}#
			plot(y,x,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	} else if(!skipOut){#
		if(add){#
			points(x,y, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(ylim[1])){#
				ylim <- at[1]+c(-1,1)#
			}#
			if(is.null(xlim[1])){#
				xlim <- range(x)#
			}#
			plot(x,y,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	}#
	if(axes & !add){#
		axis(vertical+1)#
	}#
}
par(mfrow=c(1,1))#
boxPlot(tips$tip, tips$day, horiz=TRUE, key=c('Tuesday', 'Friday'))#
dotPlot(tips$tip, tips$day, add=TRUE, at=1:2+0.05, key=c('Tuesday', 'Friday'))
histPlot(cars$price[cars$type=='small'], probability=TRUE, outline=TRUE, xlim=c(0,50))#
histPlot(cars$price[cars$type=='midsize'], probability=TRUE, outline=TRUE, add=TRUE, border='#558822', lty=3)#
histPlot(cars$price[cars$type=='large'], probability=TRUE, outline=TRUE, add=TRUE, border='#882255', lty=4)#
legend('topright', lty=2:4, col=c('#225588', '#558822', '#882255'), legend=c('small', 'midsize', 'large'))
histPlot(cars$price[cars$type=='small'], probability=TRUE, hollow=TRUE, xlim=c(0,50))#
histPlot(cars$price[cars$type=='midsize'], probability=TRUE, hollow=TRUE, add=TRUE, border='#558822', lty=3)#
histPlot(cars$price[cars$type=='large'], probability=TRUE, hollow=TRUE, add=TRUE, border='#882255', lty=4)#
legend('topright', lty=2:4, col=c('#225588', '#558822', '#882255'), legend=c('small', 'midsize', 'large'))
histPlot(cars$price[cars$type=='small'], probability=TRUE, hollow=TRUE, xlim=c(0,50))#
histPlot(cars$price[cars$type=='midsize'], probability=TRUE, hollow=TRUE, add=TRUE, border='red', lty=3)#
histPlot(cars$price[cars$type=='large'], probability=TRUE, hollow=TRUE, add=TRUE, border='blue', lty=4)#
legend('topright', lty=2:4, col=c('black', 'red', 'blue'), legend=c('small', 'midsize', 'large'))
plot(cars$weight, cars$price, col=fadeColor('chocolate4', '88'), pch=20, cex=2)
#===> vehicle price versus weight <===##
plot(cars$weight, cars$price, col=fadeColor('magenta', '88'), pch=20, cex=2)
#===> mileage versus weight <===##
plot(cars$weight, cars$mpgCity, col=fadeColor('chocolate4', '88'), pch=20, cex=2)
plot(cars$weight, cars$mpgCity, col=fadeColor('chocolate4', '88'), pch=20, cex=2)#
temp <- c(seq(1000, 5000, 100), rev(seq(1000, 5000, 100)), 1000)#
polygon(temp, 87.11 - 0.03508*temp + 0.000004432*temp^2 + 5*c(rep(-1, 41), rep(1, 41), -1), col=fadeColor('black', '22'), border=fadeColor('black', '00'))
temp <- c(seq(1000, 5000, 100), rev(seq(1000, 5000, 100)), 1000)#
polygon(temp, 87.11 - 0.03508*temp + 0.000004432*temp^2 + 7*c(rep(-1, 41), rep(1, 41), -1), col=fadeColor('black', '22'), border=fadeColor('black', '00'))
#===> mileage versus weight <===##
plot(cars$weight, cars$mpgCity, col=fadeColor('chocolate4', '88'), pch=20, cex=2)#
temp <- c(seq(1000, 5000, 100), rev(seq(1000, 5000, 100)), 1000)#
polygon(temp, 87.11 - 0.03508*temp + 0.000004432*temp^2 + 7*c(rep(-1, 41), rep(1, 41), -1), col=fadeColor('black', '22'), border=fadeColor('black', '00'))
ls()
rm(temp)
#===> identify the outliers <===##
boxPlot(marioKart$totalPr, marioKart$cond, horiz=TRUE)#
toss <- which(marioKart$totalPr > 80)#
lines(rep(marioKart$totalPr[toss[1]], 2), c(2.4, 2))#
text(marioKart$totalPr[toss[1]], 2.4, marioKart$title[toss[1]], pos=3, cex=0.5)#
lines(rep(marioKart$totalPr[toss[2]], 2), c(1.6, 2))#
text(marioKart$totalPr[toss[2]], 1.6, marioKart$title[toss[2]], pos=1, cex=0.5)#
marioKart[toss, ]
#===> replot without the outliers <===##
boxPlot(marioKart$totalPr[-toss], marioKart$cond[-toss], horiz=TRUE)
par(mfrow=1:2)#
boxPlot(run10$time)#
boxplot(run10$time)
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), outline=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, outline=TRUE, lty=3, border='#885522')#
legend('topleft', col=c('#225588', '#885522'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)))
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), outline=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='#885522')#
legend('topleft', col=c('#225588', '#885522'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)))
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('blue', '22'), border='blue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)))
par(mfrow=c(1,1))#
histPlot(cars$price[cars$type=='small'], probability=TRUE, outline=TRUE, xlim=c(0,50))#
histPlot(cars$price[cars$type=='midsize'], probability=TRUE, outline=TRUE, add=TRUE, border='#558822', lty=3)#
histPlot(cars$price[cars$type=='large'], probability=TRUE, outline=TRUE, add=TRUE, border='#882255', lty=4)#
legend('topright', lty=2:4, col=c('#225588', '#558822', '#882255'), legend=c('small', 'midsize', 'large'))
par(mfrow=c(1,1))#
histPlot(cars$price[cars$type=='small'], probability=TRUE, hollow=TRUE, xlim=c(0,50))#
histPlot(cars$price[cars$type=='midsize'], probability=TRUE, hollow=TRUE, add=TRUE, border='red', lty=3)#
histPlot(cars$price[cars$type=='large'], probability=TRUE, hollow=TRUE, add=TRUE, border='blue', lty=4)#
legend('topright', lty=2:4, col=c('black', 'red', 'blue'), legend=c('small', 'midsize', 'large'))
par(mfrow=c(1,1))#
densityPlot(tips$tip, tips$day)#
legend('topright', col=c('#882233','#223388'), lty=1:2, legend=c('Tuesday', 'Friday'))
par(mfrow=c(1,1))#
densityPlot(tips$tip, tips$day)#
legend('topright', col=c('black','red'), lty=1:2, legend=c('Tuesday', 'Friday'))
par(mfrow=c(1,1))#
boxPlot(marioKart$totalPr, marioKart$cond, horiz=TRUE)#
these <- which(marioKart$totalPr > 80)#
# see the data collection criteria for#
# why these observations do not belong.#
lines(rep(marioKart$totalPr[these[1]], 2), c(2.4, 2))#
text(marioKart$totalPr[these[1]], 2.4, marioKart$title[these[1]], pos=3, cex=0.5)#
lines(rep(marioKart$totalPr[these[2]], 2), c(1.6, 2))#
text(marioKart$totalPr[these[2]], 1.6, marioKart$title[these[2]], pos=1, cex=0.5)
par(mfrow=c(1,1))#
histPlot(cars$price, ylim=c(0, 15))
histPlot(cars$price, ylim=c(0, 25))
histPlot(cars$price, ylim=c(0, 35))#
boxPlot(cars$price, at=25, width=3)
histPlot(cars$price, ylim=c(0, 35))#
boxPlot(cars$price, at=25, width=3, horiz=TRUE, add=TRUE)
boxPlot(cars$price, width=3, horiz=TRUE, add=25)
par(mfrow=c(1,1))#
histPlot(cars$price, ylim=c(0, 35))#
boxPlot(cars$price, width=8, horiz=TRUE, add=28)#
dotPlot(cars$price, at=35, add=TRUE)
par(mfrow=c(1,1))#
histPlot(cars$price, ylim=c(0, 35), axes=FALSE)#
axis(1)#
boxPlot(cars$price, width=8, horiz=TRUE, add=28)#
dotPlot(cars$price, at=35, add=TRUE)
histPlot(cars$price, ylim=c(0, 35), axes=FALSE)#
axis(1)
boxPlot(cars$price, width=8, horiz=TRUE, add=28)
histPlot(cars$price, ylim=c(0, 35), axes=FALSE)
boxPlot(cars$price, width=8, horiz=TRUE, add=28)
`boxPlot` <-#
function(x, fact=NULL, horiz=FALSE, width=2/3, lwd=1, lcol='black', medianLwd=2, pch=20, pchCex=1.8, col=fadeColor('black', '44'), add=FALSE, key=NULL, axes=TRUE, xlab='', ylab='', xlim=NULL, ylim=NULL, ...){#
	if(!is.null(fact)[1]){#
		fact <- as.character(fact)#
	} else {#
		fact <- rep('', length(x))#
	}#
	if(is.null(key)[1]){#
		uFact <- sort(unique(fact))#
	} else {#
		uFact <- key#
	}#
	N <- length(uFact)#
	fiveNum <- matrix(NA, N, 5)#
	for(i in 1:N){#
		fiveNum[i,] <- fivenum(x[fact == uFact[i]])#
	}#
	iqrAdj <- 1.5*(fiveNum[,4] - fiveNum[,2])#
	below <- which(fiveNum[,1] < fiveNum[,2]-iqrAdj)#
	if(length(below) > 0){#
		for(i in 1:length(below)){#
			fiveNum[below[i],1] <- min(x[x > fiveNum[below[i],2]-iqrAdj[below[i]] & fact == uFact[i]])#
		}#
	}#
	above <- which(fiveNum[,5] > fiveNum[,4]+iqrAdj)#
	if(length(above) > 0){#
		for(i in 1:length(above)){#
			fiveNum[above[i],5] <- max(x[x < fiveNum[above[i],4]+iqrAdj[above[i]] & fact == uFact[i]])#
		}#
	}#
#	below <- fiveNum[,1] < fiveNum[,2]-iqrAdj#
#	fiveNum[below,1] <- fiveNum[below,2]-iqrAdj[below]#
#	above <- fiveNum[,5] > fiveNum[,4]+iqrAdj#
#	fiveNum[above,5] <- fiveNum[above,4]+iqrAdj[above]#
	w <- width/2#
	if(horiz){#
		if(is.null(ylim)){#
			yR <- c(1-2*w,N+2*w)#
		} else {#
			yR <- ylim#
		}#
		if(is.null(xlim)){#
			xR <- range(x)#
			xR <- xR + c(-1,1)*diff(xR)/30#
		} else {#
			xR <- xlim#
		}#
		if(is.logical(add[1])){#
			if(!add[1]){#
				plot(1:length(x),x,type='n',axes=FALSE, xlim=xR, xlab=xlab, ylab=ylab, ylim=yR, ...)#
			}#
			add <- 1:N#
		} #
		if(N == 1){#
			w <- w/1.3#
		}#
		for(i in 1:N){#
			bds <- add[i]+w*c(-1,1)#
			lines(rep(fiveNum[i,1],2), bds, col=lcol, lwd=lwd)#
			lines(fiveNum[i,1:2], c(add[i],add[i]), col=lcol, lwd=lwd)#
			rect(fiveNum[i,2], add[i]-w, fiveNum[i,4], add[i]+w, border=lcol, lwd=lwd)#
			lines(rep(fiveNum[i,3], 2), bds, col=lcol, lwd=medianLwd)#
			lines(fiveNum[i,4:5], c(add[i],add[i]), col=lcol, lwd=lwd)#
			lines(rep(fiveNum[i,5],2), bds, col=lcol, lwd=lwd)#
			if(i %in% above){#
				X <- x[fact == uFact[i] & x > fiveNum[i,5]]#
				points(X, rep(add[i], length(X)), pch=pch, col=col, cex=pchCex)#
			}#
			if(i %in% below){#
				X <- x[fact == uFact[i] & x < fiveNum[i,1]]#
				points(X, rep(add[i], length(X)), pch=pch, col=col, cex=pchCex)#
			}#
		}#
		if(axes & !add[1]){#
			if(N > 1){#
				axis(2, at=add, labels=uFact)#
			}#
			axis(1)#
			box()#
		}#
	} else {#
		if(is.null(ylim)){#
			yR <- range(x)#
			yR <- yR + c(-1,1)*diff(yR)/30#
		} else {#
			yR <- ylim#
		}#
		if(is.null(xlim)){#
			xR <- c(1-2*w,N+2*w)#
		} else {#
			xR <- xlim#
		}#
		if(is.logical(add[1])){#
			if(!add[1]){#
				plot(1:length(x),x,type='n',axes=FALSE, xlim=xR, xlab=xlab, ylab=ylab, ylim=yR, ...)#
			}#
			add <- 1:N#
		}#
		if(N == 1){#
			w <- w/1.3#
		}#
		for(i in 1:N){#
			bds <- add[i]+w*c(-1,1)#
			lines(bds, rep(fiveNum[i,1],2), col=lcol, lwd=lwd)#
			lines(c(add[i],add[i]), fiveNum[i,1:2], col=lcol, lwd=lwd)#
			rect(add[i]-w, fiveNum[i,2], add[i]+w, fiveNum[i,4], border=lcol, lwd=lwd)#
			lines(bds, rep(fiveNum[i,3], 2), col=lcol, lwd=medianLwd)#
			lines(c(add[i],add[i]), fiveNum[i,4:5], col=lcol, lwd=lwd)#
			lines(bds, rep(fiveNum[i,5],2), col=lcol, lwd=lwd)#
			if(i %in% above){#
				X <- x[fact == uFact[i] & x > fiveNum[i,5]]#
				points(rep(add[i], length(X)), X, pch=pch, col=col, cex=pchCex)#
			}#
			if(i %in% below){#
				X <- x[fact == uFact[i] & x < fiveNum[i,1]]#
				points(rep(add[i], length(X)), X, pch=pch, col=col, cex=pchCex)#
			}#
		}#
		if(axes & !add[1]){#
			if(N > 1){#
				axis(1, at=add, labels=uFact)#
			}#
			axis(2)#
			box()#
		}#
	}#
}
par(mfrow=c(1,1))#
histPlot(cars$price, ylim=c(0, 35), axes=FALSE)#
axis(1)#
boxPlot(cars$price, width=8, horiz=TRUE, add=28)#
dotPlot(cars$price, at=35, add=TRUE)
par(mfrow=c(1,1))#
histPlot(cars$price, ylim=c(0, 35), axes=FALSE, ylab='')#
axis(1)#
boxPlot(cars$price, width=8, horiz=TRUE, add=28)#
dotPlot(cars$price, at=35, add=TRUE)
par(mfrow=c(1,1))#
histPlot(cars$price, ylim=c(0, 2), axes=FALSE, ylab='', probability=TRUE)#
axis(1)#
boxPlot(cars$price, width=8, horiz=TRUE, add=1)#
dotPlot(cars$price, at=1.5, add=TRUE)#
densityPlot(cars$price, add=TRUE)
par(mfrow=c(1,1))#
histPlot(cars$price, ylim=c(0, 2), axes=FALSE, ylab='', probability=TRUE)#
axis(1)#
boxPlot(cars$price, width=0.5, horiz=TRUE, add=1)#
dotPlot(cars$price, at=1.5, add=TRUE)#
densityPlot(cars$price, add=TRUE)
histPlot(cars$price, ylim=c(0, 0.2), axes=FALSE, ylab='', probability=TRUE)
par(mfrow=c(1,1))#
histPlot(cars$price, ylim=c(0, 0.1), axes=FALSE, ylab='', probability=TRUE)#
axis(1)#
boxPlot(cars$price, width=0.03, horiz=TRUE, add=0.07)#
dotPlot(cars$price, at=0.095, add=TRUE)#
densityPlot(cars$price, add=TRUE)
par(mfrow=c(1,1))#
histPlot(cars$price, ylim=c(0, 0.1), axes=FALSE, ylab='', probability=TRUE)#
axis(1)#
boxPlot(cars$price, width=0.03, horiz=TRUE, add=0.067)#
dotPlot(cars$price, at=0.095, add=TRUE)#
densityPlot(cars$price, add=TRUE)
par(mfrow=c(1,1))#
histPlot(cars$price, ylim=c(0, 0.1), axes=FALSE, ylab='', probability=TRUE, xlab='price')#
axis(1)#
boxPlot(cars$price, width=0.03, horiz=TRUE, add=0.067)#
dotPlot(cars$price, at=0.095, add=TRUE)#
densityPlot(cars$price, add=TRUE)
par(mfrow=1:2)#
plot(possum$headL, possum$skullW)#
histPlot(possum$totalL[possum$sex=='f'], outline=TRUE, probability=TRUE)#
histPlot(possum$totalL[possum$sex=='m'], outline=TRUE, add=TRUE, lty=3, border='#885522', probability=TRUE)#
legend('topright', col=c('#225588', '#885522'), lty=2:3, legend=c('f', 'm'))
par(mfrow=1:2)#
plot(possum$headL, possum$skullW)#
histPlot(possum$totalL[possum$sex=='f'], hollow=TRUE, probability=TRUE)#
histPlot(possum$totalL[possum$sex=='m'], hollow=TRUE, add=TRUE, lty=3, border='blue', probability=TRUE)#
legend('topright', col=c('black', 'blue'), lty=2:3, legend=c('f', 'm'))
par(mfrow=1:2)#
plot(possum$headL, possum$skullW)#
densityPlot(possum$totalL, possum$sex)
par(mfrow=1:2)#
plot(possum$headL, possum$skullW)#
densityPlot(possum$totalL, possum$sex, key=c('f','m'))#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('f', 'm'))
par(mfrow=1:2)#
plot(possum$headL, possum$skullW)#
densityPlot(possum$totalL, possum$sex, key=c('f','m'), xlab='total length (cm)')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('f', 'm'))
`densityPlot` <-#
function(x, fact=NULL, bw = "nrd0", histo=c('none', 'faded', 'hollow'), breaks='Sturges', fading='0E', fadingBorder='25', lty=NULL, lwd=1, col=c('black', 'red', 'blue'), key=NULL, add=FALSE, adjust = 1, kernel = c("gaussian", "epanechnikov", "rectangular","triangular", "biweight", "cosine", "optcosine"), weights = NULL, n = 512, from, to, na.rm = FALSE, xlim=NULL, ylim=NULL, main='', ...){#
	if(!is.null(fact)[1]){#
		d <- list()#
		fact <- as.character(fact)#
		if(is.null(key)[1]){#
			key <- unique(fact)#
		}#
		K <- length(key)#
		if(is.null(lty)[1]){#
			lty <- 1:K#
		}#
		if(is.null(lwd)[1]){#
			lwd <- rep(1,K)#
		}#
		xR <- NULL#
		yR <- NULL#
		for(i in 1:K){#
			d[[i]] <- density(x[fact == key[i]],#
				bw=bw, adjust=adjust, kernel=kernel,#
				weights=weights, n=n, from=from, to=to,#
				na.rm=na.rm)#
			xR <- range(c(xR, d[[i]]$x))#
			yR <- max(c(yR, max(d[[i]]$y)))#
		}#
		if(is.null(xlim)[1]){#
			xlim <- xR#
		}#
		if(is.null(ylim)[1]){#
			ylim <- c(0,yR)#
		}#
		if(add){#
			for(i in 1:K){#
				densityPlot(x[fact==key[i]], add=TRUE,#
					col=col[i], lty=lty[i], lwd=lwd[i],#
					xlim=xlim, ylim=ylim)#
			}#
		} else {#
			densityPlot(x[fact==key[1]], add=FALSE,#
				col=col[1], lty=lty[1], lwd=lwd[1],#
				xlim=xlim, ylim=ylim, main=main, ...)#
			if(K > 1){#
				for(i in 2:K){#
					densityPlot(x[fact==key[i]], add=TRUE,#
						col=col[i], lty=lty[i], lwd=lwd[i])#
				}#
			}#
		}#
	} else {#
		K <- 1#
		d <- density(x, bw=bw, adjust=adjust, kernel=kernel,#
			weights=weights, n=n, from=from, to=to, na.rm=na.rm)#
		xR <- range(d$x)#
		yR <- max(d$y)#
		if(histo[1] %in% c('hollow', 'faded')){#
			H <- hist(x, breaks=breaks, plot=FALSE)#
			xR <- range(c(xR, H$breaks))#
			yR <- max(c(yR, max(H$density)))#
		}#
		if(is.null(xlim)[1]){#
			xlim <- xR#
		}#
		if(is.null(ylim)[1]){#
			ylim <- c(0,yR)#
		}#
		if(histo[1]=='hollow'){#
			histPlot(x, col=fadeColor(col[1],fading),#
				border=fadeColor(col[1],fadingBorder),#
				breaks=breaks, probability=TRUE,#
				add=add, xlim=xlim, ylim=ylim, main=main,#
				hollow=TRUE, ...)#
		} else if(histo[1]=='faded'){#
			histPlot(x, col=fadeColor(col[1],fading),#
				border=fadeColor(col[1],fadingBorder),#
				breaks=breaks, probability=TRUE,#
				add=add, xlim=xlim, ylim=ylim, main=main, ...)#
		} else if(!add){#
			plot(d, col=col[1], type='l', main=main,				xlim=xlim, ylim=ylim, ...)#
			abline(h=0)#
		}#
		if(histo[1] %in% c('hollow', 'faded') | add){#
			points(d, col=col[1], type='l',#
				lty=lty, lwd=lwd)#
		}#
	}#
}
par(mfrow=1:2)#
plot(possum$headL, possum$skullW)#
densityPlot(possum$totalL, possum$sex, key=c('f','m'), xlab='total length (cm)')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('f', 'm'))
par(mfrow=1:2)#
plot(possum$headL, possum$skullW)#
densityPlot(possum$totalL, possum$sex, key=c('f','m'), xlab='total length (cm)', histo='hollow')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('f', 'm'))
par(mfrow=1:2)#
plot(possum$headL, possum$skullW)#
densityPlot(possum$totalL, key=c('f','m'), xlab='total length (cm)', histo='hollow')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('f', 'm'))
par(mfrow=1:2)#
plot(possum$headL, possum$skullW)#
densityPlot(possum$totalL, possum$sex, key=c('f','m'), xlab='total length (cm)')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('f', 'm'))
boxPlot(possum$totalL, possum$sex)
boxPlot(possum$totalL, possum$sex, add=FALSE)
par(mfrow=1:2)#
#
#===> comparison 1 <===##
boxPlot(run10$time)#
boxplot(run10$time)
`boxPlot` <-#
function(x, fact=NULL, horiz=FALSE, width=2/3, lwd=1, lcol='black', medianLwd=2, pch=20, pchCex=1.8, col=fadeColor('black', '44'), add=FALSE, key=NULL, axes=TRUE, xlab='', ylab='', xlim=NULL, ylim=NULL, ...){#
	if(!is.null(fact)[1]){#
		fact <- as.character(fact)#
	} else {#
		fact <- rep('', length(x))#
	}#
	if(is.null(key)[1]){#
		uFact <- sort(unique(fact))#
	} else {#
		uFact <- key#
	}#
	noAxes=FALSE#
	if(!add){#
		noAxes=TRUE#
	}#
	N <- length(uFact)#
	fiveNum <- matrix(NA, N, 5)#
	for(i in 1:N){#
		fiveNum[i,] <- fivenum(x[fact == uFact[i]])#
	}#
	iqrAdj <- 1.5*(fiveNum[,4] - fiveNum[,2])#
	below <- which(fiveNum[,1] < fiveNum[,2]-iqrAdj)#
	if(length(below) > 0){#
		for(i in 1:length(below)){#
			fiveNum[below[i],1] <- min(x[x > fiveNum[below[i],2]-iqrAdj[below[i]] & fact == uFact[i]])#
		}#
	}#
	above <- which(fiveNum[,5] > fiveNum[,4]+iqrAdj)#
	if(length(above) > 0){#
		for(i in 1:length(above)){#
			fiveNum[above[i],5] <- max(x[x < fiveNum[above[i],4]+iqrAdj[above[i]] & fact == uFact[i]])#
		}#
	}#
#	below <- fiveNum[,1] < fiveNum[,2]-iqrAdj#
#	fiveNum[below,1] <- fiveNum[below,2]-iqrAdj[below]#
#	above <- fiveNum[,5] > fiveNum[,4]+iqrAdj#
#	fiveNum[above,5] <- fiveNum[above,4]+iqrAdj[above]#
	w <- width/2#
	if(horiz){#
		if(is.null(ylim)){#
			yR <- c(1-2*w,N+2*w)#
		} else {#
			yR <- ylim#
		}#
		if(is.null(xlim)){#
			xR <- range(x)#
			xR <- xR + c(-1,1)*diff(xR)/30#
		} else {#
			xR <- xlim#
		}#
		if(is.logical(add[1])){#
			if(!add[1]){#
				plot(1:length(x),x,type='n',axes=FALSE, xlim=xR, xlab=xlab, ylab=ylab, ylim=yR, ...)#
			}#
			add <- 1:N#
		} #
		if(N == 1){#
			w <- w/1.3#
		}#
		for(i in 1:N){#
			bds <- add[i]+w*c(-1,1)#
			lines(rep(fiveNum[i,1],2), bds, col=lcol, lwd=lwd)#
			lines(fiveNum[i,1:2], c(add[i],add[i]), col=lcol, lwd=lwd)#
			rect(fiveNum[i,2], add[i]-w, fiveNum[i,4], add[i]+w, border=lcol, lwd=lwd)#
			lines(rep(fiveNum[i,3], 2), bds, col=lcol, lwd=medianLwd)#
			lines(fiveNum[i,4:5], c(add[i],add[i]), col=lcol, lwd=lwd)#
			lines(rep(fiveNum[i,5],2), bds, col=lcol, lwd=lwd)#
			if(i %in% above){#
				X <- x[fact == uFact[i] & x > fiveNum[i,5]]#
				points(X, rep(add[i], length(X)), pch=pch, col=col, cex=pchCex)#
			}#
			if(i %in% below){#
				X <- x[fact == uFact[i] & x < fiveNum[i,1]]#
				points(X, rep(add[i], length(X)), pch=pch, col=col, cex=pchCex)#
			}#
		}#
		if(axes & !add[1]){#
			if(N > 1){#
				axis(2, at=add, labels=uFact)#
			}#
			axis(1)#
			box()#
		}#
	} else {#
		if(is.null(ylim)){#
			yR <- range(x)#
			yR <- yR + c(-1,1)*diff(yR)/30#
		} else {#
			yR <- ylim#
		}#
		if(is.null(xlim)){#
			xR <- c(1-2*w,N+2*w)#
		} else {#
			xR <- xlim#
		}#
		if(is.logical(add[1])){#
			if(!add[1]){#
				plot(1:length(x),x,type='n',axes=FALSE, xlim=xR, xlab=xlab, ylab=ylab, ylim=yR, ...)#
			}#
			add <- 1:N#
		}#
		if(N == 1){#
			w <- w/1.3#
		}#
		for(i in 1:N){#
			bds <- add[i]+w*c(-1,1)#
			lines(bds, rep(fiveNum[i,1],2), col=lcol, lwd=lwd)#
			lines(c(add[i],add[i]), fiveNum[i,1:2], col=lcol, lwd=lwd)#
			rect(add[i]-w, fiveNum[i,2], add[i]+w, fiveNum[i,4], border=lcol, lwd=lwd)#
			lines(bds, rep(fiveNum[i,3], 2), col=lcol, lwd=medianLwd)#
			lines(c(add[i],add[i]), fiveNum[i,4:5], col=lcol, lwd=lwd)#
			lines(bds, rep(fiveNum[i,5],2), col=lcol, lwd=lwd)#
			if(i %in% above){#
				X <- x[fact == uFact[i] & x > fiveNum[i,5]]#
				points(rep(add[i], length(X)), X, pch=pch, col=col, cex=pchCex)#
			}#
			if(i %in% below){#
				X <- x[fact == uFact[i] & x < fiveNum[i,1]]#
				points(rep(add[i], length(X)), X, pch=pch, col=col, cex=pchCex)#
			}#
		}#
		if(axes & !noAxes){#
			if(N > 1){#
				axis(1, at=add, labels=uFact)#
			}#
			axis(2)#
			box()#
		}#
	}#
}
par(mfrow=1:2)#
#
#===> comparison 1 <===##
boxPlot(run10$time)#
boxplot(run10$time)
`boxPlot` <-#
function(x, fact=NULL, horiz=FALSE, width=2/3, lwd=1, lcol='black', medianLwd=2, pch=20, pchCex=1.8, col=fadeColor('black', '44'), add=FALSE, key=NULL, axes=TRUE, xlab='', ylab='', xlim=NULL, ylim=NULL, ...){#
	if(!is.null(fact)[1]){#
		fact <- as.character(fact)#
	} else {#
		fact <- rep('', length(x))#
	}#
	if(is.null(key)[1]){#
		uFact <- sort(unique(fact))#
	} else {#
		uFact <- key#
	}#
	noAxes=TRUE#
	if(!add){#
		noAxes=FALSE#
	}#
	N <- length(uFact)#
	fiveNum <- matrix(NA, N, 5)#
	for(i in 1:N){#
		fiveNum[i,] <- fivenum(x[fact == uFact[i]])#
	}#
	iqrAdj <- 1.5*(fiveNum[,4] - fiveNum[,2])#
	below <- which(fiveNum[,1] < fiveNum[,2]-iqrAdj)#
	if(length(below) > 0){#
		for(i in 1:length(below)){#
			fiveNum[below[i],1] <- min(x[x > fiveNum[below[i],2]-iqrAdj[below[i]] & fact == uFact[i]])#
		}#
	}#
	above <- which(fiveNum[,5] > fiveNum[,4]+iqrAdj)#
	if(length(above) > 0){#
		for(i in 1:length(above)){#
			fiveNum[above[i],5] <- max(x[x < fiveNum[above[i],4]+iqrAdj[above[i]] & fact == uFact[i]])#
		}#
	}#
#	below <- fiveNum[,1] < fiveNum[,2]-iqrAdj#
#	fiveNum[below,1] <- fiveNum[below,2]-iqrAdj[below]#
#	above <- fiveNum[,5] > fiveNum[,4]+iqrAdj#
#	fiveNum[above,5] <- fiveNum[above,4]+iqrAdj[above]#
	w <- width/2#
	if(horiz){#
		if(is.null(ylim)){#
			yR <- c(1-2*w,N+2*w)#
		} else {#
			yR <- ylim#
		}#
		if(is.null(xlim)){#
			xR <- range(x)#
			xR <- xR + c(-1,1)*diff(xR)/30#
		} else {#
			xR <- xlim#
		}#
		if(is.logical(add[1])){#
			if(!add[1]){#
				plot(1:length(x),x,type='n',axes=FALSE, xlim=xR, xlab=xlab, ylab=ylab, ylim=yR, ...)#
			}#
			add <- 1:N#
		} #
		if(N == 1){#
			w <- w/1.3#
		}#
		for(i in 1:N){#
			bds <- add[i]+w*c(-1,1)#
			lines(rep(fiveNum[i,1],2), bds, col=lcol, lwd=lwd)#
			lines(fiveNum[i,1:2], c(add[i],add[i]), col=lcol, lwd=lwd)#
			rect(fiveNum[i,2], add[i]-w, fiveNum[i,4], add[i]+w, border=lcol, lwd=lwd)#
			lines(rep(fiveNum[i,3], 2), bds, col=lcol, lwd=medianLwd)#
			lines(fiveNum[i,4:5], c(add[i],add[i]), col=lcol, lwd=lwd)#
			lines(rep(fiveNum[i,5],2), bds, col=lcol, lwd=lwd)#
			if(i %in% above){#
				X <- x[fact == uFact[i] & x > fiveNum[i,5]]#
				points(X, rep(add[i], length(X)), pch=pch, col=col, cex=pchCex)#
			}#
			if(i %in% below){#
				X <- x[fact == uFact[i] & x < fiveNum[i,1]]#
				points(X, rep(add[i], length(X)), pch=pch, col=col, cex=pchCex)#
			}#
		}#
		if(axes & !add[1]){#
			if(N > 1){#
				axis(2, at=add, labels=uFact)#
			}#
			axis(1)#
			box()#
		}#
	} else {#
		if(is.null(ylim)){#
			yR <- range(x)#
			yR <- yR + c(-1,1)*diff(yR)/30#
		} else {#
			yR <- ylim#
		}#
		if(is.null(xlim)){#
			xR <- c(1-2*w,N+2*w)#
		} else {#
			xR <- xlim#
		}#
		if(is.logical(add[1])){#
			if(!add[1]){#
				plot(1:length(x),x,type='n',axes=FALSE, xlim=xR, xlab=xlab, ylab=ylab, ylim=yR, ...)#
			}#
			add <- 1:N#
		}#
		if(N == 1){#
			w <- w/1.3#
		}#
		for(i in 1:N){#
			bds <- add[i]+w*c(-1,1)#
			lines(bds, rep(fiveNum[i,1],2), col=lcol, lwd=lwd)#
			lines(c(add[i],add[i]), fiveNum[i,1:2], col=lcol, lwd=lwd)#
			rect(add[i]-w, fiveNum[i,2], add[i]+w, fiveNum[i,4], border=lcol, lwd=lwd)#
			lines(bds, rep(fiveNum[i,3], 2), col=lcol, lwd=medianLwd)#
			lines(c(add[i],add[i]), fiveNum[i,4:5], col=lcol, lwd=lwd)#
			lines(bds, rep(fiveNum[i,5],2), col=lcol, lwd=lwd)#
			if(i %in% above){#
				X <- x[fact == uFact[i] & x > fiveNum[i,5]]#
				points(rep(add[i], length(X)), X, pch=pch, col=col, cex=pchCex)#
			}#
			if(i %in% below){#
				X <- x[fact == uFact[i] & x < fiveNum[i,1]]#
				points(rep(add[i], length(X)), X, pch=pch, col=col, cex=pchCex)#
			}#
		}#
		if(axes & !noAxes){#
			if(N > 1){#
				axis(1, at=add, labels=uFact)#
			}#
			axis(2)#
			box()#
		}#
	}#
}
par(mfrow=1:2)#
#
#===> comparison 1 <===##
boxPlot(run10$time)#
boxplot(run10$time)
#===> comparison 2 <===##
boxPlot(run10$time, run10$gender, col=fadeColor('black', '22'))#
boxplot(run10$time ~ run10$gender)
#
#===> modifications using boxPlot <===##
par(mfrow=c(2,2))#
boxPlot(run10$time, run10$gender)#
boxPlot(run10$time, run10$gender, xlab='gender', ylab='run time (min)', col=fadeColor('black', '18'))#
plot(0,0, xlab='gender', ylab='run time (min)', xlim=c(0,6), ylim=c(30, 180), axes=FALSE)#
boxPlot(run10$time, run10$gender, width=0.5, lwd=2, lcol=4, medianLwd=4, pch=1, pchCex=1, col=4, add=c(1,2,5), key=c('M','F','N'))#
plot(0,0, ylab='gender', xlab='run time (min)', xlim=c(30, 180), ylim=c(0, 3), axes=FALSE)#
boxPlot(run10$time, run10$gender, horiz=TRUE, xlab='run time (min)', ylab='gender', add=1:2, key=c('F','M'))#
# 'key' can be used to restrict to only the#
# desired groups
par(mfrow=1:2)#
plot(possum$headL, possum$skullW)#
densityPlot(possum$totalL, possum$sex, key=c('f','m'), xlab='total length (cm)')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('f', 'm'))
`boxPlot` <-#
function(x, fact=NULL, horiz=FALSE, width=2/3, lwd=1, lcol='black', medianLwd=2, pch=20, pchCex=1.8, col=fadeColor('black', '44'), add=FALSE, key=NULL, axes=TRUE, xlab='', ylab='', xlim=NULL, ylim=NULL, ...){#
	if(!is.null(fact)[1]){#
		fact <- as.character(fact)#
	} else {#
		fact <- rep('', length(x))#
	}#
	if(is.null(key)[1]){#
		uFact <- sort(unique(fact))#
	} else {#
		uFact <- key#
	}#
	N <- length(uFact)#
	fiveNum <- matrix(NA, N, 5)#
	for(i in 1:N){#
		fiveNum[i,] <- fivenum(x[fact == uFact[i]])#
	}#
	iqrAdj <- 1.5*(fiveNum[,4] - fiveNum[,2])#
	below <- which(fiveNum[,1] < fiveNum[,2]-iqrAdj)#
	if(length(below) > 0){#
		for(i in 1:length(below)){#
			fiveNum[below[i],1] <- min(x[x > fiveNum[below[i],2]-iqrAdj[below[i]] & fact == uFact[i]])#
		}#
	}#
	above <- which(fiveNum[,5] > fiveNum[,4]+iqrAdj)#
	if(length(above) > 0){#
		for(i in 1:length(above)){#
			fiveNum[above[i],5] <- max(x[x < fiveNum[above[i],4]+iqrAdj[above[i]] & fact == uFact[i]])#
		}#
	}#
#	below <- fiveNum[,1] < fiveNum[,2]-iqrAdj#
#	fiveNum[below,1] <- fiveNum[below,2]-iqrAdj[below]#
#	above <- fiveNum[,5] > fiveNum[,4]+iqrAdj#
#	fiveNum[above,5] <- fiveNum[above,4]+iqrAdj[above]#
	w <- width/2#
	if(horiz){#
		if(is.null(ylim)){#
			yR <- c(1-2*w,N+2*w)#
		} else {#
			yR <- ylim#
		}#
		if(is.null(xlim)){#
			xR <- range(x)#
			xR <- xR + c(-1,1)*diff(xR)/30#
		} else {#
			xR <- xlim#
		}#
		if(is.logical(add[1])){#
			if(!add[1]){#
				plot(1:length(x),x,type='n',axes=FALSE, xlim=xR, xlab=xlab, ylab=ylab, ylim=yR, ...)#
			}#
			add <- 1:N#
		} #
		if(N == 1){#
			w <- w/1.3#
		}#
		for(i in 1:N){#
			bds <- add[i]+w*c(-1,1)#
			lines(rep(fiveNum[i,1],2), bds, col=lcol, lwd=lwd)#
			lines(fiveNum[i,1:2], c(add[i],add[i]), col=lcol, lwd=lwd)#
			rect(fiveNum[i,2], add[i]-w, fiveNum[i,4], add[i]+w, border=lcol, lwd=lwd)#
			lines(rep(fiveNum[i,3], 2), bds, col=lcol, lwd=medianLwd)#
			lines(fiveNum[i,4:5], c(add[i],add[i]), col=lcol, lwd=lwd)#
			lines(rep(fiveNum[i,5],2), bds, col=lcol, lwd=lwd)#
			if(i %in% above){#
				X <- x[fact == uFact[i] & x > fiveNum[i,5]]#
				points(X, rep(add[i], length(X)), pch=pch, col=col, cex=pchCex)#
			}#
			if(i %in% below){#
				X <- x[fact == uFact[i] & x < fiveNum[i,1]]#
				points(X, rep(add[i], length(X)), pch=pch, col=col, cex=pchCex)#
			}#
		}#
		if(axes){#
			if(N > 1){#
				axis(2, at=add, labels=uFact)#
			}#
			axis(1)#
			box()#
		}#
	} else {#
		if(is.null(ylim)){#
			yR <- range(x)#
			yR <- yR + c(-1,1)*diff(yR)/30#
		} else {#
			yR <- ylim#
		}#
		if(is.null(xlim)){#
			xR <- c(1-2*w,N+2*w)#
		} else {#
			xR <- xlim#
		}#
		if(is.logical(add[1])){#
			if(!add[1]){#
				plot(1:length(x),x,type='n',axes=FALSE, xlim=xR, xlab=xlab, ylab=ylab, ylim=yR, ...)#
			}#
			add <- 1:N#
		}#
		if(N == 1){#
			w <- w/1.3#
		}#
		for(i in 1:N){#
			bds <- add[i]+w*c(-1,1)#
			lines(bds, rep(fiveNum[i,1],2), col=lcol, lwd=lwd)#
			lines(c(add[i],add[i]), fiveNum[i,1:2], col=lcol, lwd=lwd)#
			rect(add[i]-w, fiveNum[i,2], add[i]+w, fiveNum[i,4], border=lcol, lwd=lwd)#
			lines(bds, rep(fiveNum[i,3], 2), col=lcol, lwd=medianLwd)#
			lines(c(add[i],add[i]), fiveNum[i,4:5], col=lcol, lwd=lwd)#
			lines(bds, rep(fiveNum[i,5],2), col=lcol, lwd=lwd)#
			if(i %in% above){#
				X <- x[fact == uFact[i] & x > fiveNum[i,5]]#
				points(rep(add[i], length(X)), X, pch=pch, col=col, cex=pchCex)#
			}#
			if(i %in% below){#
				X <- x[fact == uFact[i] & x < fiveNum[i,1]]#
				points(rep(add[i], length(X)), X, pch=pch, col=col, cex=pchCex)#
			}#
		}#
		if(axes){#
			if(N > 1){#
				axis(1, at=add, labels=uFact)#
			}#
			axis(2)#
			box()#
		}#
	}#
}
par(mfrow=1:2)#
plot(possum$headL, possum$skullW)#
densityPlot(possum$totalL, possum$sex, key=c('f','m'), xlab='total length (cm)')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('f', 'm'))
par(mfrow=1:2)#
#
#===> comparison 1 <===##
boxPlot(run10$time)#
boxplot(run10$time)
boxPlot(run10$time, run10$gender, col=fadeColor('black', '22'))#
boxplot(run10$time ~ run10$gender)
#===> modifications using boxPlot <===##
par(mfrow=c(2,2))#
boxPlot(run10$time, run10$gender)#
boxPlot(run10$time, run10$gender, xlab='gender', ylab='run time (min)', col=fadeColor('black', '18'))#
plot(0,0, xlab='gender', ylab='run time (min)', xlim=c(0,6), ylim=c(30, 180), axes=FALSE)#
boxPlot(run10$time, run10$gender, width=0.5, lwd=2, lcol=4, medianLwd=4, pch=1, pchCex=1, col=4, add=c(1,2,5), key=c('M','F','N'))#
plot(0,0, ylab='gender', xlab='run time (min)', xlim=c(30, 180), ylim=c(0, 3), axes=FALSE)#
boxPlot(run10$time, run10$gender, horiz=TRUE, xlab='run time (min)', ylab='gender', add=1:2, key=c('F','M'))#
# 'key' can be used to restrict to only the#
# desired groups
#===> combine boxPlot and dotPlot <===##
data(tips)#
par(mfrow=c(1,1))#
boxPlot(tips$tip, tips$day, horiz=TRUE, key=c('Tuesday', 'Friday'))#
dotPlot(tips$tip, tips$day, add=TRUE, at=1:2+0.05, key=c('Tuesday', 'Friday'))
#===> adding a box <===##
par(mfrow=1:2)#
boxPlot(run10$time[run10$gender=='M'], xlim=c(0,3))#
boxPlot(run10$time[run10$gender=='F'], add=2, axes=FALSE)#
axis(1, at=1:2, labels=c('M', 'F'))#
boxPlot(run10$time[run10$gender=='M'], ylim=c(0,3), horiz=TRUE)#
boxPlot(run10$time[run10$gender=='F'], add=2, horiz=TRUE, axes=FALSE)#
axis(2, at=1:2, labels=c('M', 'F'))
#===> vehicle price by type <===##
histPlot(cars$price[cars$type=='small'], probability=TRUE, hollow=TRUE, xlim=c(0,50))#
histPlot(cars$price[cars$type=='midsize'], probability=TRUE, hollow=TRUE, add=TRUE, border='red', lty=3)#
histPlot(cars$price[cars$type=='large'], probability=TRUE, hollow=TRUE, add=TRUE, border='blue', lty=4)#
legend('topright', lty=2:4, col=c('black', 'red', 'blue'), legend=c('small', 'midsize', 'large'))
par(mfrow=c(1,1))#
histPlot(cars$price[cars$type=='small'], probability=TRUE, hollow=TRUE, xlim=c(0,50))#
histPlot(cars$price[cars$type=='midsize'], probability=TRUE, hollow=TRUE, add=TRUE, border='red', lty=3)#
histPlot(cars$price[cars$type=='large'], probability=TRUE, hollow=TRUE, add=TRUE, border='blue', lty=4)#
legend('topright', lty=2:4, col=c('black', 'red', 'blue'), legend=c('small', 'midsize', 'large'))
#===> vehicle price versus weight <===##
plot(cars$weight, cars$price, col=fadeColor('magenta', '88'), pch=20, cex=2)
#===> mileage versus weight <===##
plot(cars$weight, cars$mpgCity, col=fadeColor('chocolate4', '88'), pch=20, cex=2)#
temp <- c(seq(1000, 5000, 100), rev(seq(1000, 5000, 100)), 1000)#
polygon(temp, 87.11 - 0.03508*temp + 0.000004432*temp^2 + 7*c(rep(-1, 41), rep(1, 41), -1), col=fadeColor('black', '22'), border=fadeColor('black', '00'))
par(mfrow=c(2,2))#
histPlot(tips$tip[tips$day == 'Tuesday'], hollow=TRUE, xlim=c(0, 30), lty=1, main='Tips by day')#
histPlot(tips$tip[tips$day == 'Friday'], hollow=TRUE, border='red', add=TRUE, main='Tips by day')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
densityPlot(tips$tip, tips$day, col=c('black', 'red'), main='Tips by day')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
data(run10)#
densityPlot(run10$time, histo='faded', breaks=15, main='Run time')#
densityPlot(run10$time, histo='hollow', breaks=30, fadingBorder='66', lty=1, main='Run time')
dotPlot(cars$price, cars$type, key=c('large', 'midsize', 'small'), cex=1:3)
#===> example 2 <===##
data(run10)#
layout(matrix(1:2,2), heights=c(2.7,1.5))#
par(las=1)#
dotPlot(run10$time[run10$gender=='M'], run10$div[run10$gender=='M'], col=fadeColor('black', '11'))#
# disorganized levels in the above plot, which we could#
# organize with key. an example of organizing the levels...#
dotPlot(run10$time[run10$gender=='M'], run10$div[run10$gender=='M'], col=fadeColor('black', '11'), key=c('20-24', '25-29', '30-34', '35-39')) # just looking at male runners who are 20 to 39#
par(las=0, mfrow=c(1,1))
dotPlot(marioKart$totalPr, marioKart$cond, ylim=c(0.5,2.5), xlim=c(25, 80)) # the ylim is low enough that we do not observe the outliers#
boxPlot(marioKart$totalPr, marioKart$cond, add=1:2+0.1, key=c('new', 'used'), horiz=TRUE, axes=FALSE)
#===> color numbers <===##
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), pch=20, col=2, cex=2, main='using regular colors')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col=4, pch=20, cex=2)#
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), col=fadeColor(2, '22'), pch=20, cex=2, main='fading the colors first')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col=fadeColor(4, '22'), pch=20, cex=2)
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('blue', '22'), border='blue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)))
#===> identify the outliers <===##
boxPlot(marioKart$totalPr, marioKart$cond, horiz=TRUE)#
toss <- which(marioKart$totalPr > 80)#
lines(rep(marioKart$totalPr[toss[1]], 2), c(2.4, 2))#
text(marioKart$totalPr[toss[1]], 2.4, marioKart$title[toss[1]], pos=3, cex=0.5)#
lines(rep(marioKart$totalPr[toss[2]], 2), c(1.6, 2))#
text(marioKart$totalPr[toss[2]], 1.6, marioKart$title[toss[2]], pos=1, cex=0.5)#
marioKart[toss, ]
#===> replot without the outliers <===##
boxPlot(marioKart$totalPr[-toss], marioKart$cond[-toss], horiz=TRUE)
#
#===> boxPlot <===##
data(run10)#
par(mfrow=1:2)#
boxPlot(run10$time)#
boxplot(run10$time)
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('blue', '22'), border='blue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)))
par(mfrow=c(1,1))#
histPlot(cars$price[cars$type=='small'], probability=TRUE, hollow=TRUE, xlim=c(0,50))#
histPlot(cars$price[cars$type=='midsize'], probability=TRUE, hollow=TRUE, add=TRUE, border='red', lty=3)#
histPlot(cars$price[cars$type=='large'], probability=TRUE, hollow=TRUE, add=TRUE, border='blue', lty=4)#
legend('topright', lty=2:4, col=c('black', 'red', 'blue'), legend=c('small', 'midsize', 'large'))
par(mfrow=c(1,1))#
densityPlot(tips$tip, tips$day)#
legend('topright', col=c('black','red'), lty=1:2, legend=c('Tuesday', 'Friday'))
par(mfrow=c(1,1))#
boxPlot(marioKart$totalPr, marioKart$cond, horiz=TRUE)#
these <- which(marioKart$totalPr > 80)#
# see the data collection criteria for#
# why these observations do not belong.#
lines(rep(marioKart$totalPr[these[1]], 2), c(2.4, 2))#
text(marioKart$totalPr[these[1]], 2.4, marioKart$title[these[1]], pos=3, cex=0.5)#
lines(rep(marioKart$totalPr[these[2]], 2), c(1.6, 2))#
text(marioKart$totalPr[these[2]], 1.6, marioKart$title[these[2]], pos=1, cex=0.5)
par(mfrow=c(1,1))#
histPlot(cars$price, ylim=c(0, 0.1), axes=FALSE, ylab='', probability=TRUE, xlab='price')#
axis(1)#
boxPlot(cars$price, width=0.03, horiz=TRUE, add=0.067)#
dotPlot(cars$price, at=0.095, add=TRUE)#
densityPlot(cars$price, add=TRUE)
par(mfrow=c(1,1))#
histPlot(cars$price, ylim=c(0, 0.1), axes=FALSE, ylab='', probability=TRUE, xlab='price')#
axis(1)#
boxPlot(cars$price, width=0.03, horiz=TRUE, add=0.067, axes=FALSE)#
dotPlot(cars$price, at=0.095, add=TRUE)#
densityPlot(cars$price, add=TRUE)
par(mfrow=1:2)#
plot(possum$headL, possum$skullW)#
densityPlot(possum$totalL, possum$sex, key=c('f','m'), xlab='total length (cm)')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('f', 'm'))
histPlot(run10$netTime[run10$gender == 'M'])
densityPlot(run10$time, run10$gender)
densityPlot(run10$time, run10$gender, key=c('F','M'))
legend('topright', lty=2:1, col=c('red','black'), legend=c('M','F'))
par(mfrow=c(2,2))#
boxPlot(tips$tip, tips$day)#
histPlot(tips$tip[tips$week == 1], outline=TRUE, probability=TRUE, ylim=c(0, 0.1), xlim=c(0, 30))#
histPlot(tips$tip[tips$week == 2], outline=TRUE, lty=3, probability=TRUE, col='#885522', add=TRUE)#
histPlot(tips$tip[tips$week == 3], outline=TRUE, lty=4, probability=TRUE, col='#558822', add=TRUE)#
legend('topright', lty=2:4, col=c('#225588', '#885522', '#558822'), legend=1:3)#
dotPlot(tips$tip)#
densityPlot(tips$tip, tips$day)#
legend('topright', col=c('#882233','#223388'), lty=1:2, legend=c('Tuesday', 'Friday'))
par(mfrow=c(2,2))#
boxPlot(tips$tip, tips$day)#
histPlot(tips$tip[tips$week == 1], hollow=TRUE, probability=TRUE, ylim=c(0, 0.1), xlim=c(0, 30))#
histPlot(tips$tip[tips$week == 2], hollow=TRUE, lty=3, probability=TRUE, col='red', add=TRUE)#
histPlot(tips$tip[tips$week == 3], hollow=TRUE, lty=4, probability=TRUE, col='blue', add=TRUE)#
legend('topright', lty=2:4, col=c('black', 'red', 'blue'), legend=1:3)#
dotPlot(tips$tip)#
densityPlot(tips$tip, tips$day)#
legend('topright', col=c('#882233','#223388'), lty=1:2, legend=c('Tuesday', 'Friday'))
par(mfrow=c(2,2))#
boxPlot(tips$tip, tips$day)#
histPlot(tips$tip[tips$week == 1], hollow=TRUE, probability=TRUE, ylim=c(0, 0.1), xlim=c(0, 30))#
histPlot(tips$tip[tips$week == 2], hollow=TRUE, lty=3, probability=TRUE, col='red', add=TRUE)#
histPlot(tips$tip[tips$week == 3], hollow=TRUE, lty=4, probability=TRUE, col='blue', add=TRUE)#
legend('topright', lty=2:4, col=c('black', 'red', 'blue'), legend=1:3)#
dotPlot(tips$tip)#
densityPlot(tips$tip, tips$day)#
legend('topright', col=c('black','red'), lty=1:2, legend=c('Tuesday', 'Friday'))
par(mfrow=c(2,2))#
boxPlot(tips$tip, tips$day)#
histPlot(tips$tip[tips$week == 1], hollow=TRUE, probability=TRUE, ylim=c(0, 0.1), xlim=c(0, 30))#
histPlot(tips$tip[tips$week == 2], hollow=TRUE, lty=3, probability=TRUE, border='red', add=TRUE)#
histPlot(tips$tip[tips$week == 3], hollow=TRUE, lty=4, probability=TRUE, border='blue', add=TRUE)#
legend('topright', lty=2:4, col=c('black', 'red', 'blue'), legend=1:3)#
dotPlot(tips$tip)#
densityPlot(tips$tip, tips$day)#
legend('topright', col=c('black','red'), lty=1:2, legend=c('Tuesday', 'Friday'))
par(mfrow=c(2,2))#
boxPlot(tips$tip, tips$day)#
densityPlot(tips$tip, tips$week, key=1:3)#
#histPlot(tips$tip[tips$week == 1], hollow=TRUE, probability=TRUE, ylim=c(0, 0.1), xlim=c(0, 30))#
#histPlot(tips$tip[tips$week == 2], hollow=TRUE, lty=3, probability=TRUE, border='red', add=TRUE)#
#histPlot(tips$tip[tips$week == 3], hollow=TRUE, lty=4, probability=TRUE, border='blue', add=TRUE)#
legend('topright', lty=1:3, col=c('black', 'red', 'blue'), legend=1:3)#
dotPlot(tips$tip)#
densityPlot(tips$tip, tips$day)#
legend('topright', col=c('black','red'), lty=1:2, legend=c('Tuesday', 'Friday'))
par(mfrow=c(2,2))#
boxPlot(tips$tip, tips$day)#
densityPlot(tips$tip, tips$week, key=1:3)#
legend('topright', lty=1:3, col=c('black', 'red', 'blue'), legend=1:3)#
dotPlot(tips$tip)#
densityPlot(tips$tip, tips$day)#
legend('topright', col=c('black','red'), lty=1:2, legend=c('Tuesday', 'Friday'))
ls()
rm(these)
rm(temp)
rm(toss)
ls()
save.image('hold.RData')
load("/Users/diez/Desktop/openintroDT/openintro/data/cars.rda")
load("/Users/diez/Desktop/openintroDT/openintro/data/marioKart.rda")
load("/Users/diez/Desktop/openintroDT/openintro/data/possum.rda")
load("/Users/diez/Desktop/openintroDT/openintro/data/run10.rda")
load("/Users/diez/Desktop/openintroDT/openintro/data/tips.rda")
`histPlot` <-#
function(x, col=fadeColor('black', '22'), border='black', breaks="default", probability=FALSE, hollow=FALSE, add=FALSE, lty=2, lwd=1, freqTable=FALSE, right=TRUE, axes=TRUE, xlab=NULL, ylab=NULL, xlim=NULL, ylim=NULL, ...){#
	if(breaks[1] == 'default'){#
		breaks <- 'Sturges'#
	}#
	if(freqTable){#
		nObs <- sum(x[,2])#
		xR   <- range(x[,1])#
		xR   <- xR + c(-1,1)*diff(xR)/10^5#
		H    <- list()#
		if(is.character(breaks)[1]){#
			breaks <- 10#
		}#
		if(length(breaks) == 1){#
			H$breaks <- pretty(xR, n=breaks, min.n=1)#
		} else {#
			H$breaks <- breaks#
		}#
		H$mids <- H$breaks[-1] - diff(H$breaks)/2#
		H$counts <- rep(0, length(H$mids))#
		for(i in 1:length(H$counts)){#
			if(right){#
				temp <- which(x[,1] <= H$breaks[i+1] & x[,1] > H$breaks[i])#
			} else {#
				temp <- which(x[,1] < H$breaks[i+1] & x[,1] >= H$breaks[i])#
			}#
			H$counts[i] <- sum(x[temp,2])#
		}#
		H$density <- (H$counts/sum(H$counts))/diff(H$breaks)#
	} else {#
		if(length(breaks) > 1 && is.numeric(breaks)[1]){#
			H <- hist(x, breaks=breaks, plot=FALSE, right=right, include.lowest=FALSE)#
		} else {#
			H <- hist(x, breaks=breaks, plot=FALSE, right=right)#
		}#
	}#
	br <- H$breaks#
	mi <- H$mids#
	y <- H$counts#
	if(probability){#
		y <- H$density#
	}#
	if(is.null(ylab)){#
		ylab <- 'frequency'#
		if(probability){#
			ylab <- 'density'#
		}#
	}#
	if(is.null(xlab)){#
		xlab <- H$xname#
	}#
	if(is.null(xlim)){#
		xlim <- range(br)#
	}#
	if(is.null(ylim)){#
		ylim=c(0,max(y))#
	}#
	if(!add){#
		plot(x, xlim=xlim, ylim=ylim, type='n', axes=FALSE, ylab=ylab, xlab=xlab, ...)#
		abline(h=0)#
		if(axes){#
			axis(1)#
			axis(2)#
		}#
	}#
	if(hollow){#
		n  <- length(H$breaks)#
		br <- c(br[1], br)#
		y  <- c(0, y, 0)#
		points(br, y, type='s', col=border, lty=lty, lwd=lwd)#
	} else {#
		miL <- length(mi)#
		for(i in 1:miL){#
			rect(br[i], 0, br[i+1], y[i],#
				border='#ffffff00', col=col)#
			lines(rep(br[i],2), c(0,y[i]), col=border)#
			lines(br[i:(i+1)], rep(y[i],2), col=border)#
			if(i > 1){#
				if(y[i] < y[i-1]){#
					lines(rep(br[i],2), y[(i-1):i], col=border)#
				}#
			}#
		}#
		lines(rep(br[miL+1],2), c(0,y[miL]), col=border)#
	}#
}
`fadeColor` <-#
function(col, fade='FF'){#
	if(is.numeric(col)[1]){#
		col <- round(col)#
		COL <- col#
		COL[col %% 8 == 0] <- '#BBBBBB'#
		COL[col %% 8 == 1] <- '#000000'#
		COL[col %% 8 == 2] <- '#BB0000'#
		COL[col %% 8 == 3] <- '#00FF00'#
		COL[col %% 8 == 4] <- '#0000FF'#
		COL[col %% 8 == 5] <- '#00FFFF'#
		COL[col %% 8 == 6] <- '#FF00FF'#
		COL[col %% 8 == 7] <- '#FFFF00'#
		col <- COL#
	} else if(substr(col[1],1,1) != '#'){#
		temp <- col2rgb(col[1])#
		col <- rgb(temp[1], temp[2], temp[3], maxColorValue=255)#
	}#
	# check fading#
	if(any(nchar(col[1]) != 7)){#
		stop('col must be either an integer or in #RRGGBB format\n')#
	}#
	if(any(nchar(fade[1]) != 2)){#
		stop('fade must be a hexadecimal string of 2 characters\n')#
	}#
	col <- paste(col, fade, sep='')#
	return(col)#
}
`dotPlot` <-#
function(x, fact=NULL, vertical=FALSE, at=1, key=NULL, pch=20, col=fadeColor('black', '66'), cex=1, add=FALSE, axes=TRUE, xlim=NULL, ylim=NULL, ...){#
	skipOut <- FALSE#
	if(!is.null(fact[1])){#
		if(!is.null(key[1])){#
			uFact <- key#
		} else {#
			uFact <- unique(fact)#
		}#
		n <- length(uFact)#
		if(length(at) == 1){#
			at <- 1:n#
		}#
		dataR <- range(x)#
		atR <- range(at)#
		if(!vertical){#
			if(is.null(xlim[1])){#
				xlim <- dataR#
			}#
			if(is.null(ylim[1])){#
				ylim <- atR + c(-1,1)*diff(atR)/7#
			}#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- atR + c(-1,1)*diff(atR)/7#
			}#
			if(is.null(ylim[1])){#
				ylim <- dataR#
			}#
		}#
		if(length(pch) == 1){#
			pch <- rep(pch, length(at))#
		}#
		if(length(col) == 1){#
			col <- rep(col, length(at))#
		}#
		if(length(cex) == 1){#
			cex <- rep(cex, length(at))#
		}#
		dotPlot(x[fact == uFact[1]], vertical=vertical, at=at[1], axes=axes, add=add, pch=pch[1], col=col[1], cex=cex[1], xlim=xlim, ylim=ylim, ...)#
		for(i in 2:n){#
			dotPlot(x[fact == uFact[i]], vertical=vertical, at=at[i], add=TRUE, pch=pch[i], col=col[i], cex=cex[i], axes=FALSE)#
		}#
		if(axes & !add){#
			if(vertical){#
				axis(1, at=at, labels=uFact)#
			} else {#
				axis(2, at=at, labels=uFact)#
			}#
		}#
		skipOut=TRUE#
	}#
	y <- rep(at[1], length(x))#
	if(vertical & !skipOut){#
		if(add){#
			points(y,x, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- at[1]+c(-1,1)#
			}#
			if(is.null(ylim[1])){#
				ylim <- range(x)#
			}#
			plot(y,x,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	} else if(!skipOut){#
		if(add){#
			points(x,y, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(ylim[1])){#
				ylim <- at[1]+c(-1,1)#
			}#
			if(is.null(xlim[1])){#
				xlim <- range(x)#
			}#
			plot(x,y,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	}#
	if(axes & !add){#
		axis(vertical+1)#
	}#
}
`densityPlot` <-#
function(x, fact=NULL, bw = "nrd0", histo=c('none', 'faded', 'hollow'), breaks='Sturges', fading='0E', fadingBorder='25', lty=NULL, lwd=1, col=c('black', 'red', 'blue'), key=NULL, add=FALSE, adjust = 1, kernel = c("gaussian", "epanechnikov", "rectangular","triangular", "biweight", "cosine", "optcosine"), weights = NULL, n = 512, from, to, na.rm = FALSE, xlim=NULL, ylim=NULL, main='', ...){#
	if(!is.null(fact)[1]){#
		d <- list()#
		fact <- as.character(fact)#
		if(is.null(key)[1]){#
			key <- unique(fact)#
		}#
		K <- length(key)#
		if(is.null(lty)[1]){#
			lty <- 1:K#
		}#
		if(is.null(lwd)[1]){#
			lwd <- rep(1,K)#
		}#
		xR <- NULL#
		yR <- NULL#
		for(i in 1:K){#
			d[[i]] <- density(x[fact == key[i]],#
				bw=bw, adjust=adjust, kernel=kernel,#
				weights=weights, n=n, from=from, to=to,#
				na.rm=na.rm)#
			xR <- range(c(xR, d[[i]]$x))#
			yR <- max(c(yR, max(d[[i]]$y)))#
		}#
		if(is.null(xlim)[1]){#
			xlim <- xR#
		}#
		if(is.null(ylim)[1]){#
			ylim <- c(0,yR)#
		}#
		if(add){#
			for(i in 1:K){#
				densityPlot(x[fact==key[i]], add=TRUE,#
					col=col[i], lty=lty[i], lwd=lwd[i],#
					xlim=xlim, ylim=ylim)#
			}#
		} else {#
			densityPlot(x[fact==key[1]], add=FALSE,#
				col=col[1], lty=lty[1], lwd=lwd[1],#
				xlim=xlim, ylim=ylim, main=main, ...)#
			if(K > 1){#
				for(i in 2:K){#
					densityPlot(x[fact==key[i]], add=TRUE,#
						col=col[i], lty=lty[i], lwd=lwd[i])#
				}#
			}#
		}#
	} else {#
		K <- 1#
		d <- density(x, bw=bw, adjust=adjust, kernel=kernel,#
			weights=weights, n=n, from=from, to=to, na.rm=na.rm)#
		xR <- range(d$x)#
		yR <- max(d$y)#
		if(histo[1] %in% c('hollow', 'faded')){#
			H <- hist(x, breaks=breaks, plot=FALSE)#
			xR <- range(c(xR, H$breaks))#
			yR <- max(c(yR, max(H$density)))#
		}#
		if(is.null(xlim)[1]){#
			xlim <- xR#
		}#
		if(is.null(ylim)[1]){#
			ylim <- c(0,yR)#
		}#
		if(histo[1]=='hollow'){#
			histPlot(x, col=fadeColor(col[1],fading),#
				border=fadeColor(col[1],fadingBorder),#
				breaks=breaks, probability=TRUE,#
				add=add, xlim=xlim, ylim=ylim, main=main,#
				hollow=TRUE, ...)#
		} else if(histo[1]=='faded'){#
			histPlot(x, col=fadeColor(col[1],fading),#
				border=fadeColor(col[1],fadingBorder),#
				breaks=breaks, probability=TRUE,#
				add=add, xlim=xlim, ylim=ylim, main=main, ...)#
		} else if(!add){#
			plot(d, col=col[1], type='l', main=main,				xlim=xlim, ylim=ylim, ...)#
			abline(h=0)#
		}#
		if(histo[1] %in% c('hollow', 'faded') | add){#
			points(d, col=col[1], type='l',#
				lty=lty, lwd=lwd)#
		}#
	}#
}
`boxPlot` <-#
function(x, fact=NULL, horiz=FALSE, width=2/3, lwd=1, lcol='black', medianLwd=2, pch=20, pchCex=1.8, col=fadeColor('black', '44'), add=FALSE, key=NULL, axes=TRUE, xlab='', ylab='', xlim=NULL, ylim=NULL, ...){#
	if(!is.null(fact)[1]){#
		fact <- as.character(fact)#
	} else {#
		fact <- rep('', length(x))#
	}#
	if(is.null(key)[1]){#
		uFact <- sort(unique(fact))#
	} else {#
		uFact <- key#
	}#
	N <- length(uFact)#
	fiveNum <- matrix(NA, N, 5)#
	for(i in 1:N){#
		fiveNum[i,] <- fivenum(x[fact == uFact[i]])#
	}#
	iqrAdj <- 1.5*(fiveNum[,4] - fiveNum[,2])#
	below <- which(fiveNum[,1] < fiveNum[,2]-iqrAdj)#
	if(length(below) > 0){#
		for(i in 1:length(below)){#
			fiveNum[below[i],1] <- min(x[x > fiveNum[below[i],2]-iqrAdj[below[i]] & fact == uFact[i]])#
		}#
	}#
	above <- which(fiveNum[,5] > fiveNum[,4]+iqrAdj)#
	if(length(above) > 0){#
		for(i in 1:length(above)){#
			fiveNum[above[i],5] <- max(x[x < fiveNum[above[i],4]+iqrAdj[above[i]] & fact == uFact[i]])#
		}#
	}#
#	below <- fiveNum[,1] < fiveNum[,2]-iqrAdj#
#	fiveNum[below,1] <- fiveNum[below,2]-iqrAdj[below]#
#	above <- fiveNum[,5] > fiveNum[,4]+iqrAdj#
#	fiveNum[above,5] <- fiveNum[above,4]+iqrAdj[above]#
	w <- width/2#
	if(horiz){#
		if(is.null(ylim)){#
			yR <- c(1-2*w,N+2*w)#
		} else {#
			yR <- ylim#
		}#
		if(is.null(xlim)){#
			xR <- range(x)#
			xR <- xR + c(-1,1)*diff(xR)/30#
		} else {#
			xR <- xlim#
		}#
		if(is.logical(add[1])){#
			if(!add[1]){#
				plot(1:length(x),x,type='n',axes=FALSE, xlim=xR, xlab=xlab, ylab=ylab, ylim=yR, ...)#
			}#
			add <- 1:N#
		} #
		if(N == 1){#
			w <- w/1.3#
		}#
		for(i in 1:N){#
			bds <- add[i]+w*c(-1,1)#
			lines(rep(fiveNum[i,1],2), bds, col=lcol, lwd=lwd)#
			lines(fiveNum[i,1:2], c(add[i],add[i]), col=lcol, lwd=lwd)#
			rect(fiveNum[i,2], add[i]-w, fiveNum[i,4], add[i]+w, border=lcol, lwd=lwd)#
			lines(rep(fiveNum[i,3], 2), bds, col=lcol, lwd=medianLwd)#
			lines(fiveNum[i,4:5], c(add[i],add[i]), col=lcol, lwd=lwd)#
			lines(rep(fiveNum[i,5],2), bds, col=lcol, lwd=lwd)#
			if(i %in% above){#
				X <- x[fact == uFact[i] & x > fiveNum[i,5]]#
				points(X, rep(add[i], length(X)), pch=pch, col=col, cex=pchCex)#
			}#
			if(i %in% below){#
				X <- x[fact == uFact[i] & x < fiveNum[i,1]]#
				points(X, rep(add[i], length(X)), pch=pch, col=col, cex=pchCex)#
			}#
		}#
		if(axes){#
			if(N > 1){#
				axis(2, at=add, labels=uFact)#
			}#
			axis(1)#
			box()#
		}#
	} else {#
		if(is.null(ylim)){#
			yR <- range(x)#
			yR <- yR + c(-1,1)*diff(yR)/30#
		} else {#
			yR <- ylim#
		}#
		if(is.null(xlim)){#
			xR <- c(1-2*w,N+2*w)#
		} else {#
			xR <- xlim#
		}#
		if(is.logical(add[1])){#
			if(!add[1]){#
				plot(1:length(x),x,type='n',axes=FALSE, xlim=xR, xlab=xlab, ylab=ylab, ylim=yR, ...)#
			}#
			add <- 1:N#
		}#
		if(N == 1){#
			w <- w/1.3#
		}#
		for(i in 1:N){#
			bds <- add[i]+w*c(-1,1)#
			lines(bds, rep(fiveNum[i,1],2), col=lcol, lwd=lwd)#
			lines(c(add[i],add[i]), fiveNum[i,1:2], col=lcol, lwd=lwd)#
			rect(add[i]-w, fiveNum[i,2], add[i]+w, fiveNum[i,4], border=lcol, lwd=lwd)#
			lines(bds, rep(fiveNum[i,3], 2), col=lcol, lwd=medianLwd)#
			lines(c(add[i],add[i]), fiveNum[i,4:5], col=lcol, lwd=lwd)#
			lines(bds, rep(fiveNum[i,5],2), col=lcol, lwd=lwd)#
			if(i %in% above){#
				X <- x[fact == uFact[i] & x > fiveNum[i,5]]#
				points(rep(add[i], length(X)), X, pch=pch, col=col, cex=pchCex)#
			}#
			if(i %in% below){#
				X <- x[fact == uFact[i] & x < fiveNum[i,1]]#
				points(rep(add[i], length(X)), X, pch=pch, col=col, cex=pchCex)#
			}#
		}#
		if(axes){#
			if(N > 1){#
				axis(1, at=add, labels=uFact)#
			}#
			axis(2)#
			box()#
		}#
	}#
}
par(mfrow=1:2)#
#
#===> comparison 1 <===##
boxPlot(run10$time)#
boxplot(run10$time)
#
#===> comparison 2 <===##
boxPlot(run10$time, run10$gender, col=fadeColor('black', '22'))#
boxplot(run10$time ~ run10$gender)
#
#===> comparison 2 <===##
boxPlot(run10$time, run10$gender, col=fadeColor('black', '22'))#
boxplot(run10$time ~ run10$gender)
par(mfrow=1:2)#
#
#===> comparison 1 <===##
boxPlot(run10$time)#
boxplot(run10$time)
#
#===> comparison 2 <===##
boxPlot(run10$time, run10$gender, col=fadeColor('black', '22'))#
boxplot(run10$time ~ run10$gender)
#
#===> modifications using boxPlot <===##
par(mfrow=c(2,2))#
boxPlot(run10$time, run10$gender)#
boxPlot(run10$time, run10$gender, xlab='gender', ylab='run time (min)', col=fadeColor('black', '18'))#
plot(0,0, xlab='gender', ylab='run time (min)', xlim=c(0,6), ylim=c(30, 180), axes=FALSE)#
boxPlot(run10$time, run10$gender, width=0.5, lwd=2, lcol=4, medianLwd=4, pch=1, pchCex=1, col=4, add=c(1,2,5), key=c('M','F','N'))#
plot(0,0, ylab='gender', xlab='run time (min)', xlim=c(30, 180), ylim=c(0, 3), axes=FALSE)#
boxPlot(run10$time, run10$gender, horiz=TRUE, xlab='run time (min)', ylab='gender', add=1:2, key=c('F','M'))#
# 'key' can be used to restrict to only the#
# desired groups
#===> modifications using boxPlot <===##
par(mfrow=c(2,2))#
#
boxPlot(run10$time, run10$gender)#
#
boxPlot(run10$time, run10$gender, xlab='gender', ylab='run time (min)', col=fadeColor('black', '18'))#
#
plot(0,0, xlab='gender', ylab='run time (min)', xlim=c(0,6), ylim=c(30, 180), axes=FALSE)#
boxPlot(run10$time, run10$gender, width=0.5, lwd=2, lcol=4, medianLwd=4, pch=1, pchCex=1, col=4, add=c(1,2,5), key=c('M','F','N'))#
#
plot(0,0, ylab='gender', xlab='run time (min)', xlim=c(30, 180), ylim=c(0, 3), axes=FALSE)#
boxPlot(run10$time, run10$gender, horiz=TRUE, xlab='run time (min)', ylab='gender', add=1:2, key=c('F','M'))#
# 'key' can be used to restrict to only the#
# desired groups
par(mfrow=c(1,1))#
boxPlot(tips$tip, tips$day, horiz=TRUE, key=c('Tuesday', 'Friday'))#
dotPlot(tips$tip, tips$day, add=TRUE, at=1:2+0.05, key=c('Tuesday', 'Friday'))
#===> adding a box <===##
par(mfrow=1:2)#
boxPlot(run10$time[run10$gender=='M'], xlim=c(0,3))#
boxPlot(run10$time[run10$gender=='F'], add=2, axes=FALSE)#
axis(1, at=1:2, labels=c('M', 'F'))#
boxPlot(run10$time[run10$gender=='M'], ylim=c(0,3), horiz=TRUE)#
boxPlot(run10$time[run10$gender=='F'], add=2, horiz=TRUE, axes=FALSE)#
axis(2, at=1:2, labels=c('M', 'F'))
#
#===> vehicle price by type <===##
par(mfrow=c(1,1))#
histPlot(cars$price[cars$type=='small'], probability=TRUE, hollow=TRUE, xlim=c(0,50))#
histPlot(cars$price[cars$type=='midsize'], probability=TRUE, hollow=TRUE, add=TRUE, border='red', lty=3)#
histPlot(cars$price[cars$type=='large'], probability=TRUE, hollow=TRUE, add=TRUE, border='blue', lty=4)#
legend('topright', lty=2:4, col=c('black', 'red', 'blue'), legend=c('small', 'midsize', 'large'))
#
#===> vehicle price versus weight <===##
plot(cars$weight, cars$price, col=fadeColor('magenta', '88'), pch=20, cex=2)
#
#===> mileage versus weight <===##
plot(cars$weight, cars$mpgCity, col=fadeColor('chocolate4', '88'), pch=20, cex=2)#
temp <- c(seq(1000, 5000, 100), rev(seq(1000, 5000, 100)), 1000)#
polygon(temp, 87.11 - 0.03508*temp + 0.000004432*temp^2 + 7*c(rep(-1, 41), rep(1, 41), -1), col=fadeColor('black', '22'), border=fadeColor('black', '00'))
par(mfrow=c(2,2))#
histPlot(tips$tip[tips$day == 'Tuesday'], hollow=TRUE, xlim=c(0, 30), lty=1, main='Tips by day')#
histPlot(tips$tip[tips$day == 'Friday'], hollow=TRUE, border='red', add=TRUE, main='Tips by day')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
densityPlot(tips$tip, tips$day, col=c('black', 'red'), main='Tips by day')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('Tuesday', 'Friday'))#
data(run10)#
densityPlot(run10$time, histo='faded', breaks=15, main='Run time')#
densityPlot(run10$time, histo='hollow', breaks=30, fadingBorder='66', lty=1, main='Run time')
dotPlot(cars$price, cars$type, key=c('large', 'midsize', 'small'), cex=1:3)
#
#===> example 2 <===##
data(run10)#
layout(matrix(1:2,2), heights=c(2.7,1.5))#
par(las=1)#
dotPlot(run10$time[run10$gender=='M'], run10$div[run10$gender=='M'], col=fadeColor('black', '11'))#
# disorganized levels in the above plot, which we could#
# organize with key. an example of organizing the levels...#
dotPlot(run10$time[run10$gender=='M'], run10$div[run10$gender=='M'], col=fadeColor('black', '11'), key=c('20-24', '25-29', '30-34', '35-39')) # just looking at male runners who are 20 to 39#
par(las=0, mfrow=c(1,1))#
#
#===> example 3 <===##
data(marioKart)#
dotPlot(marioKart$totalPr, marioKart$cond, ylim=c(0.5,2.5), xlim=c(25, 80)) # the ylim is low enough that we do not observe the outliers#
boxPlot(marioKart$totalPr, marioKart$cond, add=1:2+0.1, key=c('new', 'used'), horiz=TRUE, axes=FALSE)
#
#===> example 2 <===##
data(run10)#
layout(matrix(1:2,2), heights=c(2.7,1.5))#
par(las=1)#
dotPlot(run10$time[run10$gender=='M'], run10$div[run10$gender=='M'], col=fadeColor('black', '11'))#
# disorganized levels in the above plot, which we could#
# organize with key. an example of organizing the levels...#
dotPlot(run10$time[run10$gender=='M'], run10$div[run10$gender=='M'], col=fadeColor('black', '11'), key=c('20-24', '25-29', '30-34', '35-39')) # just looking at male runners who are 20 to 39#
par(las=0, mfrow=c(1,1))
#
#===> example 3 <===##
data(marioKart)#
dotPlot(marioKart$totalPr, marioKart$cond, ylim=c(0.5,2.5), xlim=c(25, 80)) # the ylim is low enough that we do not observe the outliers#
boxPlot(marioKart$totalPr, marioKart$cond, add=1:2+0.1, key=c('new', 'used'), horiz=TRUE, axes=FALSE)
par(mfrow=1:2)#
#
#===> color numbers <===##
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), pch=20, col=2, cex=2, main='using regular colors')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col=4, pch=20, cex=2)#
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), col=fadeColor(2, '22'), pch=20, cex=2, main='fading the colors first')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col=fadeColor(4, '22'), pch=20, cex=2)
#
#===> color names <===##
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), pch=20, col='red', cex=2, main='using regular colors')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col='blue', pch=20, cex=2)#
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), col=fadeColor('red', '22'), pch=20, cex=2, main='fading the colors first')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col=fadeColor('blue', '22'), pch=20, cex=2)
#
#===> hexadecimal <===##
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), pch=20, col='#FF0000', cex=2, main='using regular colors')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col='#0000FF', pch=20, cex=2)#
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), col=fadeColor('#FF0000', '22'), pch=20, cex=2, main='fading the colors first')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col=fadeColor('#0000FF', '22'), pch=20, cex=2)
#
#===> hexadecimal <===##
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), pch=20, col='#FF0000', cex=2, main='using regular colors')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col='#0000FF', pch=20, cex=2)#
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), col=fadeColor('#FF0000', '22'), pch=20, cex=2, main='fading the colors first')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col=fadeColor('#0000FF', '22'), pch=20, cex=2)
#
#===> alternative: rgb function <===##
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), pch=20, col=rgb(1,0,0), cex=2, main='using regular colors')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col=rgb(0,0,1), pch=20, cex=2)#
dotPlot(marioKart$totalPr[marioKart$cond == 'new'], ylim=c(0,3), xlim=c(25, 80), col=rgb(1,0,0,1/8), pch=20, cex=2, main='fading the colors first')#
dotPlot(marioKart$totalPr[marioKart$cond == 'used'], at=2, add=TRUE, col=rgb(0,0,1,1/8), pch=20, cex=2)
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('blue', '22'), border='blue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)))
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('green', '22'), border='blue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)))
histPlot(run10$time, col=fadeColor('red', '22'), border='blue', probability=TRUE, breaks=30, lwd=3)
histPlot(run10$time, col=fadeColor('red', '22'), border='blue', probability=TRUE, breaks=30, lwd=3)
histPlot(run10$time, col=fadeColor('red', '22'), border='blue', probability=TRUE, breaks=30, lwd=3)
histPlot(run10$time, col=fadeColor('red', '22'), border='blue', probability=TRUE, breaks=30, lwd=3)
histPlot(run10$time, col=fadeColor('yellow', '22'), border='blue', probability=TRUE, breaks=30, lwd=3)
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('yellow', '44'), border='blue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)))
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('yellow', '33'), border='blue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)))
histPlot(run10$time, col=fadeColor('yellow', '33'), border='darkblue', probability=TRUE, breaks=30, lwd=3)
histPlot(run10$time, col=fadeColor('yellow', '33'), border='darkblue', probability=TRUE, breaks=30, lwd=3)
histPlot(run10$time, col=fadeColor('yellow', '33'), border='darkblue', probability=TRUE, breaks=30, lwd=3)
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('yellow', '33'), border='darkblue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)))
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('yellow', '33'), border='darkblue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)), col=fadeColor('lavendar', '22'))
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('yellow', '33'), border='darkblue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)), col=fadeColor('purple', '22'))
colors()[551]
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('yellow', '33'), border='darkblue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)), col=fadeColor('purple4', '22'))
colors()[79]
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('yellow', '33'), border='darkblue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)), col=fadeColor('darkgoldenrod4', '22'))
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('yellow', '33'), border='darkblue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)), col=fadeColor('darkgoldenrod4', '44'))
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('yellow', '33'), border='darkblue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)), col=fadeColor('darkgoldenrod4', '3'))
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('yellow', '33'), border='darkblue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)), col=fadeColor('darkgoldenrod4', '33'))
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('yellow', '33'), border='darkblue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)), col=fadeColor('darkgoldenrod4', '33'))
par(mfrow=1:2)#
boxPlot(run10$time)#
boxplot(run10$time)
par(mfrow=1:2)#
boxPlot(run10$time)#
boxplot(run10$time)
par(mfrow=c(2,2))#
histPlot(run10$time)#
histPlot(run10$time[run10$gender=='M'], probability=TRUE, xlim=c(30, 180), ylim=c(0, 0.025), hollow=TRUE)#
histPlot(run10$time[run10$gender=='F'], probability=TRUE, add=TRUE, hollow=TRUE, lty=3, border='red')#
legend('topleft', col=c('black', 'red'), lty=2:3, legend=c('M','F'))#
histPlot(run10$time, col=fadeColor('yellow', '33'), border='darkblue', probability=TRUE, breaks=30, lwd=3)#
histPlot(run10$time, probability=TRUE, breaks=c(c(40, 50, 60, 65, 70, 75, 80, seq(82.5, 120, 2.5), 125, 130, 135, 140, 150, 160, 170)), col=fadeColor('darkgoldenrod4', '33'))
par(mfrow=c(1,1))#
histPlot(cars$price[cars$type=='small'], probability=TRUE, hollow=TRUE, xlim=c(0,50))#
histPlot(cars$price[cars$type=='midsize'], probability=TRUE, hollow=TRUE, add=TRUE, border='red', lty=3)#
histPlot(cars$price[cars$type=='large'], probability=TRUE, hollow=TRUE, add=TRUE, border='blue', lty=4)#
legend('topright', lty=2:4, col=c('black', 'red', 'blue'), legend=c('small', 'midsize', 'large'))
par(mfrow=c(1,1))#
densityPlot(tips$tip, tips$day)#
legend('topright', col=c('black','red'), lty=1:2, legend=c('Tuesday', 'Friday'))
par(mfrow=c(1,1))#
boxPlot(marioKart$totalPr, marioKart$cond, horiz=TRUE)#
these <- which(marioKart$totalPr > 80)#
# see the data collection criteria for#
# why these observations do not belong.#
lines(rep(marioKart$totalPr[these[1]], 2), c(2.4, 2))#
text(marioKart$totalPr[these[1]], 2.4, marioKart$title[these[1]], pos=3, cex=0.5)#
lines(rep(marioKart$totalPr[these[2]], 2), c(1.6, 2))#
text(marioKart$totalPr[these[2]], 1.6, marioKart$title[these[2]], pos=1, cex=0.5)
par(mfrow=c(1,1))#
histPlot(cars$price, ylim=c(0, 0.1), axes=FALSE, ylab='', probability=TRUE, xlab='price')#
axis(1)#
boxPlot(cars$price, width=0.03, horiz=TRUE, add=0.067, axes=FALSE)#
dotPlot(cars$price, at=0.095, add=TRUE)#
densityPlot(cars$price, add=TRUE)
par(mfrow=c(1,1))#
histPlot(cars$price, ylim=c(0, 0.1), axes=FALSE, ylab='', probability=TRUE, xlab='price')#
axis(1)#
boxPlot(cars$price, width=0.03, horiz=TRUE, add=0.067, axes=FALSE)#
dotPlot(cars$price, at=0.095, add=TRUE, cex=2)#
densityPlot(cars$price, add=TRUE)
#===> identify the outliers <===##
boxPlot(marioKart$totalPr, marioKart$cond, horiz=TRUE)#
toss <- which(marioKart$totalPr > 80)#
lines(rep(marioKart$totalPr[toss[1]], 2), c(2.4, 2))#
text(marioKart$totalPr[toss[1]], 2.4, marioKart$title[toss[1]], pos=3, cex=0.5)#
lines(rep(marioKart$totalPr[toss[2]], 2), c(1.6, 2))#
text(marioKart$totalPr[toss[2]], 1.6, marioKart$title[toss[2]], pos=1, cex=0.5)#
marioKart[toss, ]#
# the other two points marked on the boxplot are legitimate auctions
boxPlot(marioKart$totalPr[-toss], marioKart$cond[-toss], horiz=TRUE)
par(mfrow=1:2)#
plot(possum$headL, possum$skullW)#
densityPlot(possum$totalL, possum$sex, key=c('f','m'), xlab='total length (cm)')#
legend('topright', col=c('black', 'red'), lty=1:2, legend=c('f', 'm'))
#===> men's times <===##
histPlot(run10$time[run10$gender == 'M'])#
#
#===> times by gender <===##
densityPlot(run10$time, run10$gender, key=c('M','F'))#
legend('topright', lty=2:1, col=c('red','black'), legend=c('M','F'))
par(mfrow=c(2,2))#
boxPlot(tips$tip, tips$day)#
densityPlot(tips$tip, tips$week, key=1:3)#
legend('topright', lty=1:3, col=c('black', 'red', 'blue'), legend=1:3)#
dotPlot(tips$tip)#
densityPlot(tips$tip, tips$day)#
legend('topright', col=c('black','red'), lty=1:2, legend=c('Tuesday', 'Friday'))
`dotPlot` <-#
function(x, fact=NULL, vertical=FALSE, at=1, key=NULL, pch=20, col=fadeColor('black', '66'), cex=1.5, add=FALSE, axes=TRUE, xlim=NULL, ylim=NULL, ...){#
	skipOut <- FALSE#
	if(!is.null(fact[1])){#
		if(!is.null(key[1])){#
			uFact <- key#
		} else {#
			uFact <- unique(fact)#
		}#
		n <- length(uFact)#
		if(length(at) == 1){#
			at <- 1:n#
		}#
		dataR <- range(x)#
		atR <- range(at)#
		if(!vertical){#
			if(is.null(xlim[1])){#
				xlim <- dataR#
			}#
			if(is.null(ylim[1])){#
				ylim <- atR + c(-1,1)*diff(atR)/7#
			}#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- atR + c(-1,1)*diff(atR)/7#
			}#
			if(is.null(ylim[1])){#
				ylim <- dataR#
			}#
		}#
		if(length(pch) == 1){#
			pch <- rep(pch, length(at))#
		}#
		if(length(col) == 1){#
			col <- rep(col, length(at))#
		}#
		if(length(cex) == 1){#
			cex <- rep(cex, length(at))#
		}#
		dotPlot(x[fact == uFact[1]], vertical=vertical, at=at[1], axes=axes, add=add, pch=pch[1], col=col[1], cex=cex[1], xlim=xlim, ylim=ylim, ...)#
		for(i in 2:n){#
			dotPlot(x[fact == uFact[i]], vertical=vertical, at=at[i], add=TRUE, pch=pch[i], col=col[i], cex=cex[i], axes=FALSE)#
		}#
		if(axes & !add){#
			if(vertical){#
				axis(1, at=at, labels=uFact)#
			} else {#
				axis(2, at=at, labels=uFact)#
			}#
		}#
		skipOut=TRUE#
	}#
	y <- rep(at[1], length(x))#
	if(vertical & !skipOut){#
		if(add){#
			points(y,x, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(xlim[1])){#
				xlim <- at[1]+c(-1,1)#
			}#
			if(is.null(ylim[1])){#
				ylim <- range(x)#
			}#
			plot(y,x,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	} else if(!skipOut){#
		if(add){#
			points(x,y, pch=pch[1], col=col[1], cex=cex[1], ...)#
		} else {#
			if(is.null(ylim[1])){#
				ylim <- at[1]+c(-1,1)#
			}#
			if(is.null(xlim[1])){#
				xlim <- range(x)#
			}#
			plot(x,y,axes=FALSE,xlim=xlim, ylim=ylim, pch=pch[1], col=col[1], cex=cex[1], ...)#
		}#
	}#
	if(axes & !add){#
		axis(vertical+1)#
	}#
}
dotPlot(marioKart$totalPr, marioKart$cond, ylim=c(0.5,2.5), xlim=c(25, 80)) # the ylim is low enough that we do not observe the outliers#
boxPlot(marioKart$totalPr, marioKart$cond, add=1:2+0.1, key=c('new', 'used'), horiz=TRUE, axes=FALSE)
dotPlot(marioKart$totalPr, marioKart$cond, ylim=c(0.5,2.5), xlim=c(25, 80)) # the ylim is low enough that we do not observe the outliers#
boxPlot(marioKart$totalPr, marioKart$cond, add=1:2+0.1, key=c('new', 'used'), horiz=TRUE, axes=FALSE)
dotPlot(marioKart$totalPr, marioKart$cond, ylim=c(0.5,2.5), xlim=c(25, 80), cex=1) # the ylim is low enough that we do not observe the outliers#
boxPlot(marioKart$totalPr, marioKart$cond, add=1:2+0.1, key=c('new', 'used'), horiz=TRUE, axes=FALSE)
par(mfrow=c(1,1))#
histPlot(cars$price, ylim=c(0, 0.1), axes=FALSE, ylab='', probability=TRUE, xlab='price')#
axis(1)#
boxPlot(cars$price, width=0.03, horiz=TRUE, add=0.067, axes=FALSE)#
dotPlot(cars$price, at=0.095, add=TRUE)#
densityPlot(cars$price, add=TRUE)
ls()
rm(these)
rm(toss)
rm(temp)
ls()
save.image('openintro.RData')
histPlot(cars$price)
histPlot(cars$price, main='test')
histPlot(cars$price, main='test', xlab='test')
histPlot(cars$price, main='test', xlab='test', ylab='test')
densityPlot(cars$price, main='test', xlab='test', ylab='test')
dotPlot(cars$price, main='test', xlab='test', ylab='test')
boxPlot(cars$price, main='test', xlab='test', ylab='test')
boxPlot(cars$price, main='test', xlab='test', ylab='test', xlim=c(0,50), ylim=c(0,50))
histPlot(cars$price, main='test', xlab='test', ylab='test', xlim=c(0,50), ylim=c(0,50))
densityPlot(cars$price, main='test', xlab='test', ylab='test', xlim=c(0,50), ylim=c(0,50))
densityPlot(cars$price, main='test', xlab='test', ylab='test', xlim=c(0,50), ylim=c(0,0.5))
dotPlot(cars$price, main='test', xlab='test', ylab='test', xlim=c(0,50), ylim=c(0,50))
