How to create a histogram in R with x coordinates having odd labels and frequency totals shown

I am creating a simulated dataset and I want to create a histogram based on x values ​​that are not numeric. Here is what I have:

x <- c("CF", "CH", "CJ", "CE", "CN", "EC", "EN", "EJ", "AB", "BA", "KO", "OD", "DL", "HG")
px = c(0.08, 0.10, 0.06, 0.20, 0.04, 0.15, 0.02, 0.10, 0.025, 0.025, 0.05, 0.05, 0.05, 0.05)
draws = sample(x, size = 1000, replace = TRUE, prob = px)
hist( draws)

I would like the histogram to have values ​​for x as labels, as well as each of the bars, to show the total frequency at which each x value was selected. Any help would be appreciated!

+4
source share
1 answer

Do you mean barkar?

> barplot(height=table(draws))

enter image description here

+8
source

Source: https://habr.com/ru/post/1526675/


All Articles