Shelina
Shelina

Reputation: 103

How to create histogram table? R

I am trying to create a histogram using frequency data. Here is the data:

  x         freq
1 Buick      80
2 Cadillac   80
3 Chevrolet  320 
4 Pontiac    150
5 SAAB       114
6 Saturn     60

When I try:

hist(carMake)

I get:

enter image description here

Then I tried:

df = as.data.frame(cbind(Overall.Cond = 1:6, Freq = c(80,80,320,150,114,60)))
df
df.freq = as.vector(rep(df$Overall.Cond, df$Freq))
hist(df.freq)

And I get:

enter image description here

Which is fine, but I would like there to be no spaces in between the bars, & labels instead of the numbers 1 through 6.

How can I do this?

Upvotes: 1

Views: 2366

Answers (1)

lukeA
lukeA

Reputation: 54237

Use barplot, since you already got your frequencies?

df <- read.table(header=T, text="
x         freq
1 Buick      80
2 Cadillac   80
3 Chevrolet  320 
4 Pontiac    150
5 SAAB       114
6 Saturn     60")
df
barplot(df$freq, names.arg = df$x)

Upvotes: 1

Related Questions