简体   繁体   中英

Use hist() to plot a density histogram in R

Alright so i need to make a Histogram of density. I have all the data that i need to plot a histogram in R using the hist() function. What i mean by the " density histogram is that i want the density to be on the Y axis and the class to be on x axis.

This is my data:

Class     Freq  ClassWidth  Density 
30.0-32.0   8   2.0             4.0 
32.0-33.0   7   1.0             7.0
33.0-34.0   10  1.0             10.0
34.0-34.5   25  0.5             50.0
34.5-35.0   30  0.5             60.0
35.0-35.5   40  0.5             80.0
35.5-36.0   45  0.5             90.0
36.0-50.0   5   14              0.357142857

Now what i did in r was

I loaded the file with all this data and wrote

data3 <- read.csv("C:/Users/jaina/Desktop/Question3bCSV.csv", header = T)
hist(data3$Density)

Can someone help me solve my issue.

Thank You

hist wants to compute its own heights from raw data, but you can get what you want with a barplot.

barplot(data3$Density, names.arg=data3$Class, space=0, ylim=c(0,100))

密度条形图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM