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.
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.
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.
you can try using the histogram()
function in lattice
a <- c(0,0,0,1,1,2)
library(lattice)
histogram(a)
defaults to percent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With