Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use hist to plot relative frequencies in R?

Tags:

r

histogram

How do you use hist() to plot relative frequencies in R?

If I do the following, I will get a density plot, but I want a relative frequency plot:

a <- c(0,0,0,1,1,2)
hist(a, freq=FALSE)

I want to see a histogram with the following relative frequencies:

.5 for 0 to 1,

.33 for 1 to 2,

and .166 for 2 to 3.

like image 895
Will Avatar asked Nov 01 '10 21:11

Will


People also ask

How do you make a relative frequency histogram in R?

To create a Relative Frequency Histogram in the R Language, we use the histogram() function of the lattice package library. The histogram() function takes the data vector as an argument and returns a relative frequency histogram.

What does hist () do in R?

The generic function hist computes a histogram of the given data values. If plot = TRUE , the resulting object of class "histogram" is plotted by plot. histogram , before it is returned.


1 Answers

you can try using the histogram() function in lattice

a <- c(0,0,0,1,1,2)
library(lattice)
histogram(a)

defaults to percent.

like image 158
Greg Avatar answered Sep 18 '22 15:09

Greg