Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a histogram in R with x coordinates having nonnumeric 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 the values for x as labels and also each of the bars to show the total frequency that each value of x was sampled. Any help would be appreciated!!

like image 673
amber4478 Avatar asked Feb 13 '23 19:02

amber4478


1 Answers

You mean a barchart?

> barplot(height=table(draws))

enter image description here

like image 98
Scott Ritchie Avatar answered Feb 16 '23 12:02

Scott Ritchie