Horizontal histogram

Description

Draw a histogram with bars horizontally

Usage

1
2
3
4
5
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, ...)

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 histogramm 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

Details

Uses barplot to draw the histogram horizontally.

Value

function to address y-coordinates

Note

Doesn't work with breakpoints provided as a vector with different widths of the bars.
Please do not forget to use the function for vertical positioning from the current horizontal histogram. If It is not working correctly, you might have the function defined from some prior horizHist result.

Author(s)

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

See Also

hist, barplot, axis

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# 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()

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.