Learn R Programming

berryFunctions (version 1.22.5)

horizHist: Horizontal histogram

Description

Draw a histogram with bars horizontally

Usage

horizHist(
  Data,
  breaks = "Sturges",
  freq = TRUE,
  plot = TRUE,
  col = par("bg"),
  border = par("fg"),
  las = 1,
  xlab = if (freq) "Frequency" else "Density",
  main = paste("Histogram of", deparse(substitute(Data))),
  ylim = range(HBreaks),
  labelat = pretty(ylim),
  labels = labelat,
  ...
)

Value

function to address y-coordinates

Arguments

Data

any data that hist would take.

breaks

character or numerical as explained in hist. DEFAULT: "Sturges"

freq

logical. if TRUE, the histogram graphic is a representation of frequencies, the counts component of the result; if FALSE, probability densities, component density, are plotted (so that the histogram has a total area of one). DEFAULT: TRUE

plot

logical. Should histogram be plotted? FALSE to get just the hpos function. DEFAULT: TRUE

col

color. DEFAULT: par("bg")

border

color of borders of bars. DEFAULT: par("fg")

las

integer. Label axis style. DEFAULT: 1

xlab

character. Label for x-axis. DEFAULT: "absolute frequency"

main

character. Title for graphic. DEFAULT: "Histogram of substitute(Data)"

ylim

numerical vector of two elements. Y-axis limits. DEFAULT: range of data

labelat

numerical vector. Position of Y-Axis labels. DEFAULT: pretty(ylim)

labels

numerical or character. The labels themselves. DEFAULT: labelat

...

further arguments passed to barplot and axis

Author

Berry Boessenkool, berry-b@gmx.de, 2011-2012

Details

Uses barplot to draw the histogram horizontally.

See Also

Examples

Run this code

# Data and basic concept
set.seed(8); ExampleData <- rnorm(50,8,5)+5
hist(ExampleData)
hpos <- horizHist(ExampleData)
# Caution: the labels at the y-axis are not the real coordinates!
# abline(h=2) will draw above the second bar, not at the label value 2.
# Use hpos (horizontal position), the function returned by horizHist:
abline(h=hpos(11), col=2, lwd=2)

# Further arguments
horizHist(ExampleData, xlim=c(-8,20))
horizHist(ExampleData, ylab="the ... argument worked!", col.axis=3)
hist(ExampleData, xlim=c(-10,40)) # with xlim
horizHist(ExampleData, ylim=c(-10,40), border="red") # with ylim
hpos <- horizHist(ExampleData, breaks=20, col="orange")
axis(2, hpos(0:10), labels=FALSE, col=2) # another use of hpos()

Run the code above in your browser using DataLab