# NOT RUN {
# 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 red bars, black background, and black border
Histogram(y, bg.fill="black",
fill="red", bg.stroke="black")
# or set this color scheme for all subsequent analyses
# here with the grid turned off as well
style(grid.stroke="off", bg.fill="black", bar.stroke="black")
Histogram(y)
# histogram with purple color theme, translucent gold bars
style("purple", sub.theme="black")
Histogram(y)
# back to default color theme
style("lightbronze")
# 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.x=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")
# 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)
# ----------------
# Trellis graphics
# ----------------
mydata <- rd("Employee", format="lessR", quiet=TRUE)
Histogram(Salary, by1=Dept)
# ---------------------
# 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.fill="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