Zuhaib Ahmed
Zuhaib Ahmed

Reputation: 507

R - Generate Histogram, given a vector of bar heights

I have a vector of length 14, where each entry in the vector is to represent the height of a histogram bar. For example, given this vector

> sample(1:20, 14)
 [1]  3 11  5 14 12  6 18  2  8  4 17 13 19 15

I want to generate a histogram with 14 bars, where the first bar has height 3, the second has height 11, etc. For some reason, this is harder than I think it should be. I can't seem to find anything about it online, or maybe I'm not good at searching. If this has been answered elsewhere, please direct me to it.

Upvotes: 0

Views: 200

Answers (1)

Jilber Urbina
Jilber Urbina

Reputation: 61214

x <- c(3, 11,  5, 14, 12,  6, 18,  2,  8,  4, 17, 13, 19, 15)
barplot(x)

Upvotes: 1

Related Questions