Your vector age
is essentially a factor vector.
So, instead of trying to plot the density of it, you can count for each levels of the factor and plot them as a histogram.
To do that, you can use dplyr
and ggplot2
:
library(dplyr)
data.frame(age) %>% group_by(age) %>% count(age)
# A tibble: 3 x 2
# Groups: age [3]
age n
<fct> <int>
1 19-25 9
2 26-32 15
3 33-39 4
And now if you are combining this output to the ggplot2
, you can get:
library(dplyr)
library(ggplot2)
data.frame(age) %>% group_by(age) %>% count(age) %>%
ggplot(aes(x = age, y = n)) + geom_bar(stat = "identity")
And you get the following histogram:

Using base R
On the good suggestion from @RoB, it could be interesting for you to know how to do it using R base
plot.
So you can achieve it like this:
library(dplyr)
df <- data.frame(age) %>% group_by(age) %>% count(age)
barplot(df$n)
axis(side = 1, at = 1:3, labels = df$age)

EDIT: Alternative for base graphic plot
Actually, you can even go faster for plotting histogram of various levels of the factor age
without the need of axis
function or dplyr
package by doing:
barplot(table(age))

Does it answer your question ?
Data
age = c("19-25","19-25","26-32","26-32","26-32","26-32","26-32","26-32","26-32",
"33-39","19-25","19-25","26-32","19-25","19-25","26-32","19-25","26-32",
"26-32","19-25","26-32","33-39","26-32","19-25","26-32","33-39","33-39","26-32")