Given a frequency table below:
> print(dat)
V1 V2
1 1 11613
2 2 6517
3 3 2442
4 4 687
5 5 159
6 6 29
# V1 = Score
# V2 = Frequency
How can we plot the density, (i.e. y-axis range from 0 to 1.0).
Currently the I have the following for frequency plot:
plot(0,main="table",type="n");
lines(dat,lty=1)
# I need to use lines() and plot() here,
# because need to make multiple lines in single plot
Not sure how to approach that for density.
The density of each block would be
V2 / sum(V2)assuming that each row is a separate block.For your data
I get:
Which we can check using R’s tools. First expand your compact frequency table
Then use
hist()to compute the values we wantLook at the resulting object:
Note the
densitycomponent which is:Which concurs with my by-hand calculation from the original frequency table representation.
As for the plotting, if you just want to draw densities instead then try:
If you want to force axis limits do: