- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a histogram using weights in R?
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 −
library("plotrix")
Consider the below vector and the weight associated with that vector −
Example
x<-sort(rpois(5000,5)) weight<-seq(1,5000)
Creating weighted histogram for x −
Output
Let’s have a look at another example −
Example
y<-sort(sample(0:100,2000,replace=TRUE)) weight<-seq(1,2000) \ weighted.hist(y,weight)
Output
- Related Articles
- How to create a transparent histogram using ggplot2 in R?
- How to create a step histogram using ggplot2 in R?
- How to create horizontal histogram in R?
- How to create histogram with varying binwidth using ggplot2 in R?
- How to create a histogram without bins in base R?
- How to create a histogram for uniform data in R?
- How to create histogram with relative frequency in R?
- How to create a horizontal line in a histogram in base R?
- How to create a histogram with Y-axis values as count using ggplot2 in R?
- How to display mean in a histogram using ggplot2 in R?
- How to create a histogram with dots instead of bars in base R?
- How to define the breaks for a histogram using ggplot2 in R?
- How to create histogram of all columns in an R data frame?
- How to create histogram for discrete column in an R data frame?
- How to create histogram like plot with different color of bars in R?

Advertisements