I am looking for advice on the best way to represent the frequency counts for the range in a column from my dataframe.
Example:
my_table<- data.frame('xcat' = c(1,1,1,2,2,2,5,10,10,10,11,11,11,14,14,14,
15,15,15, 17,17,17, 18,18,18,20,20,20))
In the above dataframe, I want to plot the frequencies from 1 to 20. One way to do it would be using hist(), setting bin size to 1, i.e.:
my_hist<- hist(my_table$xcat,
breaks=seq(from = 0.5, to= (max(my_table$xcat)+0.5),
by =1))
As you can see, I have added an offset of 0.5, so each bin will be showed on the correspondent integer. Another way to do it would be to create a table with the counts, then generate intervals:
my_tablecut = cut(my_table$xcat, breaks= seq(from =0.5, to =20.5,
by = 1), right=FALSE)
my_tablefreq = as.data.frame(table(my_tablecut))
my_tablefreq$pos<- 1:nrow(my_tablefreq)
plot(my_tablefreq$pos, my_tablefreq$Freq, type = 'l')
As I am writing, I realize it may be more correct to use a bar chart, rather than a histogram; in this case though, I would still need to generate the categories with frequency 0, probably still using the 'cut' function, and then going for 'barplot' instead of 'plot'.
I wonder if there is any downside to any of this methods, or what would be a more proper way to show what I want. Please let me know if my purpose is not clear, or I need to add more details.

