Jim_dddd Jim_dddd - 1 year ago 117
R Question

Flip coin simulation with R programming

I'm new to R and I'm doing a practice question.
Simulate rolling a fair coin 200 times, then plot a histogram of the data.
I did:

outcomes <- c("heads", "tails")
sim_fair_coin <- sample(outcomes, size = 200, replace = TRUE)

It does give me a histogram, but I think I expect a more intuitive histogram. With the X-axis shows "heads" or "tails"; and the Y-axis shows how many times I got for "heads" and "tails".
I believe there is a way to accomplish this in R. Can someone tell me more about it please?

Answer Source

You can use the ggplot2 package as well.

x <- as.data.frame(sim_fair_coin)
ggplot(x, aes(factor(sim_fair_coin))) + geom_bar(width=.5)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download