I would like to plot all the 1s of a binomial matrix (code given below). I need to histogram y-axis to be the frequency and the x-axis to be all the matrix columns.
#code for matrix
prevalence <- 0.01
Infected <- sapply(1:10, function(p) rbinom(500, 1, prevalence))
I tried using hist(Infected) but this just gave me the frequency of 0 and 1, with no column details.
Thank you for your help.
Use colSums to get the number of 1 and then barplot to get a bar per column.
set.seed(42)
prevalence <- 0.01
Infected <- sapply(1:10, function(p) rbinom(500, 1, prevalence))
barplot(colSums(Infected), names.arg = 1:10)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With