4

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!!

amber4478
  • 6,433
  • 3
  • 20
  • 17

1 Answers1

8

You mean a barchart?

> barplot(height=table(draws))

enter image description here

Scott Ritchie
  • 10,293
  • 3
  • 28
  • 64