print('RNORM EXAMPLE (f=NULL)')
x <- lapply(sample(1:5), function(avg) (rnorm(500,avg)))
names(x) <- letters[1:length(x)]
plot.sparge(x, pt.cols=rep('blue',length(x)), main='sparge plots:\nfor distributional comparison')
## four random distributrions (from the 'boxplot' examples)
print('BOXPLOT EXAMPLE DISTROS')
N.rds <- 1000
distros <- list(Uniform = runif(N.rds, min=.01, max=3), Normal = rnorm(N.rds),
`T.df5` = rt(N.rds, df = 5),
Gamma.s2 = rgamma(N.rds, shape = 2))
plot.sparge(distros, ylab='Distribution')
points(sapply(distros, median), 1:length(distros), col=gray(.6), pch="+", cex=2)
lines(sapply(distros, median), 1:length(distros), col='green')
# three more random distributions (from the 'sinaplot' examples)
print('MORE RANDOM DISTRIBUTIONS')
uniform <- runif(500, -4, 4)
bimodal <- c(rnorm(300, -2, 0.6), rnorm(300, 2, 0.6))
normal <- rnorm(800,0,3)
distributions <- list(uniform = uniform, bimodal = bimodal, normal = normal)
plot.sparge(distributions, ylab='more distributions',
boxplot.border='lightgreen', boxplot.lwd=2.3)
## using 'f' [as a factor] argument as grouping factor on just one treatment
# Orchard spray by treatment (compare with 'strip chart' plot)
print('ORCHARD')
OS <- with(OrchardSprays, split(decrease, treatment))
plot.sparge(OS, log = "x", main = "Orchard Sprays", xlab='Decrease',ylab='Treatment')
# Tooth Growth
print('TOOTH GROWTH 1')
plot.sparge(x=ToothGrowth$len, f=ToothGrowth$supp, xlab='Length', ylab='Supplement')
# multi-predictor using model-based parsing of 'f' [as a formula] and 'x' as a dataset
print('TOOTH GROWTH 2')
plot.sparge(x=ToothGrowth, f="len ~ dose", horiz=FALSE, boxplot.notch=TRUE,
ylab='Tooth Length', main='Tooth Growth') #xlab='Dose')
print('TOOTH GROWTH 3')
plot.sparge(x=ToothGrowth, f="len ~ dose | supp", horiz=FALSE,
ylab='Tooth length', main='Tooth Growth', xlab='Dose')
# CO2 dataset
print('CO2')
plot.sparge(CO2, 'uptake ~ Type | Treatment', horiz=FALSE,
ylab='Uptake', main='CO2', xlab='Type', boxplot.lty=4)
# Joyner-Boore earthquake data (heavily rounded)
print('EARTHQUAKE')
attenu$magnitude <- as.factor(round(attenu$mag))
attenu$distance <- as.factor(round(log10(attenu$dist)))
plot.sparge(x=attenu, f="accel ~ distance | magnitude", horiz=FALSE,
xlab='log10(Distance)',ylab='Acceleration', main='Earthquake Attenuation',
boxplot.lwd=1.5, cpw=.7, boxplot.col=rgb(.8,.5,0,.15))
# Motor Trend cars data (rounded)
print('CARS')
mtcars$cylinders <- as.factor(mtcars$cyl)
plot.sparge(x=mtcars, f="qsec ~ gear | cylinders", horiz=FALSE,
xlab='# of Gears', ylab='Seconds', main='Motor Trend Cars',
boxplot.lwd=2.3, boxplot.lty=2)
# NPK Yeilds
print('NPK YIELDS')
npk$N <- factor(npk$N, labels=c('','Nitrogen'))
npk$P <- factor(npk$P, labels=c('','Phosphorus'))
npk$K <- factor(npk$K, labels=c('','Potasium'))
plot.sparge(npk, f="yield ~ N | K", xlab="Yield, pounds per (1/70) acre plot")
# Wool (warp breaks per loom)
print('WOOLOOM BREAKS')
plot.sparge(warpbreaks, f="breaks ~ wool | tension", boxplot.col=rgb(1, 1, 0, 0.15),
xlab="# of Breaks", ylab='Wool')
# US states
print('STATES')
states <- data.frame(region=state.region, area=state.area, division=state.division)
plot.sparge(x=states, f="area ~ region | division", ylab="Region", xlab='Area', cpw=1)
# Michelson Speed of Light Data
print('LIGHT')
morley$run <- cut(morley$Run, breaks=0:4*5)
plot.sparge(x=morley, f="Speed ~ Expt | run", main="Michelson Speed of Light Experiment",
xlab='Speed', ylab='Experiment', boxplot.lwd=1.4, boxplot.col=rgb(.7,.7,0,.2))
# Penguins
#plot.sparge(penguins, f="body_mass ~ island | species")
# Fertility
print('FERTILITY')
infert$education <- as.factor(infert$education)
infert$ages <- jitter(infert$age, amount=1/2)
infert$spontaneous <- factor(infert$spontaneous, labels=c(0,1,2))
infertilty.model <- "ages ~ spontaneous | education "
pds <- plot.sparge(x=infert, f=infertilty.model, horiz=FALSE, cpw=.6, legend.inset=.05,
ylab='Ages, yrs (jittered)', xlab='# of Prior Miscarriages' , main='[in]Fertility',
boxplot.lty=2, boxplot.lwd=1.4, boxplot.col=rgb(.6,0,.4,.2), boxplot.varwidth=TRUE)
lines.sparge(x=infert, f=infertilty.model, pds=pds, horiz=FALSE, cat.order=2:1, pt.cex=3, lty=3)
lines.sparge(x=infert, f=infertilty.model, pds=pds, horiz=FALSE, cat.order=1:2, lwd=2, pt.cex=2)
Run the code above in your browser using DataLab