# generate 50 random normal data values with three decimal digits
y <- round(rnorm(50),3)
# --------------------
# different histograms
# --------------------
# histogram with all defaults
Histogram(y)
# short form
hs(y)
# compare to standard R function hist
hist(y)
# output saved for later analysis into object h
h <- hs(y)
# view full text output
h
# view just the outlier analysis
h$out_outliers
# list the names of all the components
names(h)
# histogram with no borders for the bars
Histogram(y, stroke="off")
# save the histogram to a pdf file
Histogram(y, pdf=TRUE)
# histogram with no grid, red bars, black background, and black border
Histogram(y, grid="off", bg="black",
fill="red", stroke="black")
# or set this color scheme for all subsequent analyses
set("red", grid="off", bg="black", stroke.bar="black")
Histogram(y)
# histogram with orange color theme, transparent orange bars, no grid lines
theme(colors="orange", ghost=TRUE)
Histogram(y)
# back to default of "blue" color theme
theme(colors="blue")
# histogram with specified bin width
# can also use bin.start
Histogram(y, bin.width=.25)
# histogram with rotated axis values, offset more from axis
# suppress text output
Histogram(y, rotate.values=45, offset=1, quiet=TRUE)
# histogram with specified bins and grid lines displayed over the histogram
Histogram(y, breaks=seq(-5,5,.25), xlab="My Variable", over.grid=TRUE)
# histogram with bins calculated with the Scott method and values displayed
Histogram(y, breaks="Scott", hist.counts=TRUE, quiet=TRUE)
# histogram with the number of suggested bins, with proportions
Histogram(y, breaks=15, prop=TRUE)
# histogram with specified colors, overriding defaults
# bg and grid are defined in histogram
# all other parameters are defined in hist, par and plot functions
# generates caution messages that can be ignored regarding density and angle
#Histogram(y, fill="darkblue", stroke="lightsteelblue4", bg="ivory",
# 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
Histogram(y, cumul="both")
# cumulative histogram plus regular histogram
# present with proportions on vertical axis, override other defaults
Histogram(y, cumul="both", breaks=seq(-4,4,.25), prop=TRUE,
reg="mistyrose")
# -------------------------------------------------
# histograms for data frames and multiple variables
# -------------------------------------------------
# create data frame, mydata, to mimic reading data with Read function
# mydata contains both numeric and non-numeric data
mydata <- data.frame(rnorm(50), rnorm(50), rnorm(50), rep(c("A","B"),25))
names(mydata) <- c("X","Y","Z","C")
# although data not attached, access the variable directly by its name
Histogram(X)
# histograms for all numeric variables in data frame called mydata
# except for numeric variables with unique values < n.cat
# mydata is the default name, so does not need to be specified with data
Histogram()
# variable of interest is in a data frame which is not the default mydata
# access the breaks variable in the R provided warpbreaks data set
# although data not attached, access the variable directly by its name
Histogram(breaks, data=warpbreaks)
# all histograms with specified options, including red axis labels
Histogram(fill="palegreen1", bg="ivory", hist.counts=TRUE, col.lab="red")
# histograms for all specified numeric variables
# use the combine or c function to specify a list of variables
Histogram(c(X,Y))
Run the code above in your browser using DataLab