Skip to contents

inthist it is common to want to generate a list of counts as integers from an input vector and then plot then as columns of those counts. Alternatively, it is common to have a two-column matrix of values and counts or totals where one wants to plot columns of those counts or totals against those values. inhist allows one to enter either a vector of integers to be counted and plotted OR a matrix of values in column 1 and counts or totals in column 2. The option of rounding non-integers is available.

Usage

inthist(
  x,
  col = 1,
  border = NULL,
  width = 0.9,
  xlab = "",
  ylab = "",
  main = "",
  lwd = 1,
  xmin = NA,
  xmax = NA,
  ymax = NA,
  plotout = TRUE,
  prop = FALSE,
  inc = 1,
  xaxis = TRUE,
  roundoff = TRUE,
  ...
)

Arguments

x

a vector of integers to be counted and plotted OR a matrix of values in column 1 and counts or totals in column 2

col

the colour of the fill; defaults to black = 1, set this to 0 for an empty bar, but then give a value for border

border

the colour of the outline of each bar defaults to col

width

denotes the width of each bar; defaults to 0.9, should be >0 and <= 1

xlab

the label for the x axis; defaults to ""

ylab

the label for the y axis; defaults to ""

main

the title for the individual plot; defaults to ""

lwd

the line width of the border; defaults to 1

xmin

sets the lower bound for x-axis; used to match plots, defaults to NA whereupon the minimum of values is used

xmax

sets the upper bound for x axis; used with multiple plots, defaults to NA whereupon the maximum of values is used

ymax

enables external control of the maximum y value; mainly of use when plotting multiple plots together.

plotout

plot the histogram or not? Defaults to TRUE

prop

plot the proportions rather than the counts, default=FALSE

inc

sets the xaxis increment; used to customize the axis; defaults to 1.

xaxis

set to FALSE to define the xaxis outside of inthist; defaults to TRUE

roundoff

if values are not integers should they be rounded off to become integers? default=TRUE. Obviously only useful when inputting a matrix.

...

available to pass extra plot arguments, such as panel.first=grid(), or whatever to the internal plot call

Value

a matrix of values and counts with the proportions of counts and values is returned invisibly

Examples

  x <- trunc(runif(1000)*10) + 1
  inthist(x,col="grey",border=3,width=0.75,xlabel="Random Uniform",
          ylabel="Frequency")
#> Warning: "xlabel" is not a graphical parameter
#> Warning: "ylabel" is not a graphical parameter
#> Warning: "xlabel" is not a graphical parameter
#> Warning: "ylabel" is not a graphical parameter
#> Warning: "xlabel" is not a graphical parameter
#> Warning: "ylabel" is not a graphical parameter
#> Warning: "xlabel" is not a graphical parameter
#> Warning: "ylabel" is not a graphical parameter
#> Warning: "xlabel" is not a graphical parameter
#> Warning: "ylabel" is not a graphical parameter
#> Warning: "xlabel" is not a graphical parameter
#> Warning: "ylabel" is not a graphical parameter

  x <- as.matrix(cbind(c(1,2,3,4,5,6,7,8),trunc(runif(8,1,20))))
  inthist(x,col="grey",border=3,width=0.75,xlabel="integers",
          ylabel="Frequency")
#> Warning: "xlabel" is not a graphical parameter
#> Warning: "ylabel" is not a graphical parameter
#> Warning: "xlabel" is not a graphical parameter
#> Warning: "ylabel" is not a graphical parameter
#> Warning: "xlabel" is not a graphical parameter
#> Warning: "ylabel" is not a graphical parameter
#> Warning: "xlabel" is not a graphical parameter
#> Warning: "ylabel" is not a graphical parameter
#> Warning: "xlabel" is not a graphical parameter
#> Warning: "ylabel" is not a graphical parameter
#> Warning: "xlabel" is not a graphical parameter
#> Warning: "ylabel" is not a graphical parameter