Try:
x1= c(5, 9, 5, 12, 35, 55, 43, 35, 18, 12, 9, 22, 22, 55, 7, 12)
x2 = c(8, 12, 24, 16, 15, 20, 20, 24, 35, 5, 7, 9, 6, 8, 6, 18, 14, 12, 16, 12, 5, 6, 9, 10, 10, 12, 18, 15, 16)
library(ggplot2)
ggplot()+geom_density(aes(x2),color='red')+geom_density(aes(x1), color='blue')

(hist(x2)) # this is the command; rest is output
$breaks
[1] 5 10 15 20 25 30 35
$counts
[1] 12 7 7 2 0 1
$density
[1] 0.082758621 0.048275862 0.048275862 0.013793103 0.000000000 0.006896552
$mids
[1] 7.5 12.5 17.5 22.5 27.5 32.5
$xname
[1] "x2"
$equidist
[1] TRUE
attr(,"class")
[1] "histogram"
For a tabular version:
hh = hist(x2)
bb = hh$breaks
hh.breaks = as.character()
for(i in 2:length(bb)) {
hh.breaks[i-1]=paste0(bb[i-1],'-',bb[i])
}
dd = data.frame(hh.breaks, hh$counts, hh$density, hh$mids)
dd
hh.breaks hh.counts hh.density hh.mids
1 5-10 12 0.082758621 7.5
2 10-15 7 0.048275862 12.5
3 15-20 7 0.048275862 17.5
4 20-25 2 0.013793103 22.5
5 25-30 0 0.000000000 27.5
6 30-35 1 0.006896552 32.5

You may find this link useful: http://www.statmethods.net/graphs/density.html
There are many others if you simply search.