A histogram using weights represent the weighted distribution of the values. In R, we can use weighted.hist function of plotrix package to create this type of histogram and we just need the values and weights corresponding to each value. Since plotrix is not frequently used, we must make sure that we install this package using install.packages("plotrix") then load it in R environment.
Loading plotrix package −
Consider the below vector and the weight associated with that vector −
Creating weighted histogram for x −
Let’s have a look at another example −
y<-sort(sample(0:100,2000,replace=TRUE)) weight<-seq(1,2000) \ weighted.hist(y,weight)