Search code examples
rhistogram

Constructing a probability histogram for p(y)


I am having some difficulty plotting the probability histogram for the table below

y 1 2 3 4

p(y) 0.4 0.3 0.2 0.1

I've tried the command: hist(p <- c(0.4, 0.3, 0.2, 0.1), y <- c(1, 2, 3, 4), main = "Frequency Histogram") but it didn't work. Is there a way for this to construct the probability histogram?


Solution

  • p <- setNames(c(0.4, 0.3, 0.2, 0.1), 1:4); barplot(p)
    

    Created on 2022-06-30 by the reprex package (v2.0.1)