# generate 100 random normal data values with three decimal digits
y <- round(rnorm(100),3)
# --------------------
# different histograms
# --------------------
# histogram with all defaults
color.hist(y)
# compare to standard R function hist
hist(y)
# histogram with specified bin width
color.hist(y, bin.width=.25)
# histogram with specified bins and grid lines displayed over the histogram
color.hist(y, breaks=seq(-5,5,.25), xlab="My Variable", over.grid=TRUE)
# histogram with bins calculated with the Scott method and values displayed
color.hist(y, breaks="Scott", show.values=TRUE)
# histogram with the number of suggested bins, with proportions
color.hist(y, breaks=25, prop=TRUE)
# histogram with specified colors, overriding defaults
# col.bg and col.grid are defined in color.hist
# all other parameters are defined in hist, par and plot functions
color.hist(y, col="darkblue", border="lightsteelblue4", col.bg="ivory",
col.grid="darkgray", density=25, angle=-45, cex.lab=.8, cex.axis=.8,
col.lab="sienna3", main="My Title", col.main="gray40", xlim=c(-5,5), lwd=2,
xlab="My Favorite Variable")
# ---------------------
# cumulative histograms
# ---------------------
# cumulative histogram with superimposed regular histogram, all defaults
color.hist(y, cumul="both")
# cumulative histogram plus regular histogram
# present with proportions on vertical axis, override other defaults
color.hist(y, cumul="both", breaks=seq(-4,4,.25), prop=TRUE,
col.reg="mistyrose")
# ---------------------------------
# histograms for multiple variables
# ---------------------------------
# read data into data frame called mydata
#rad("http://web.pdx.edu/~gerbing/data/employees2.csv")
# histograms for all numeric variables in data frame called mydata
#color.hist()
# histograms for all numeric variables in data frame called mydata
# with specified options
#color.hist(col="palegreen1", col.bg="ivory", show.values=TRUE)
# Use the subset function to specify a variable list
#color.hist(subset(mydata, select=c(Age,HealthPlan)))
Run the code above in your browser using DataLab