Tonmoy Sarkar
Tonmoy Sarkar

Reputation: 1

How can I construct Histogram, Bar plot, frequency curve and Ogive curve in R for this problem?

Dr. Tillman is Dean of the School of Business Socastee University. He wishes prepare to a report showing the number of hours per week students spends studying. He selects a random sample of 30 students and determines the number of hours each student studied last week.
15.0, 23.7, 19.7, 15.4, 18.3, 23.0, 14.2, 20.8, 13.5, 20.7, 17.4, 18.6, 12.9, 20.3, 13.7, 21.4, 18.3, 29.8, 17.1, 18.9, 10.3, 26.1, 15.7, 14.0, 17.8, 33.8, 23.2, 12.9, 27.1, 16.6

I tried histogram using R code as follows:

v <- c(15.0, 23.7, 19.7, 15.4, 18.3, 23.0, 14.2, 20.8, 13.5, 20.7, 17.4, 18.6, 12.9, 20.3, 13.7, 21.4, 18.3, 29.8, 17.1, 18.9, 10.3, 26.1, 15.7, 14.0, 17.8, 33.8, 23.2, 12.9, 27.1, 16.6)
hist(v)

Also I tried bar plot like this:

v <- c(15.0, 23.7, 19.7, 15.4, 18.3, 23.0, 14.2, 20.8, 13.5, 20.7, 17.4, 18.6, 12.9, 20.3, 13.7, 21.4, 18.3, 29.8, 17.1, 18.9, 10.3, 26.1, 15.7, 14.0, 17.8, 33.8, 23.2, 12.9, 27.1, 16.6)
barplot(v)

But I couldn't code for the "Frequency curve" and "Ogive Curve". How can I code for these in R?

Thank you!

Upvotes: 0

Views: 361

Answers (1)

dcarlson
dcarlson

Reputation: 11076

You can get the frequency data from the histogram and the ogive by sorting the values:

out <- hist(v, breaks=8)
plot(out$mids, out$counts, xlab="Hours", ylab="Freqency", type="l")
v.srt <- sort(v)
# Cumulative Frequency
plot(v.srt, cumsum(v.srt), xlab="Hours", ylab="Cumulative Frequency", type="l")
# Cumulative proportion
plot(v.srt, cumsum(v.srt)/sum(v.srt), xlab="Hours", ylab="Cumulative Frequency", type="l")
abline(h=1, lty=2)

Frequency

Cumulative

Upvotes: 1

Related Questions