R programming: Flip coin simulation

0 votes

I'm a new bee to the R language and I'm trying to solve a query. I need to simulate rolling a fair coin 200 times and then plot a histogram of the data. So I performed:

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

This does give me a histogram, but I think I expect a more detailed one. 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. 

Is there any way or code that I can implement to achieve this?

Jan 21 in Data Analytics by Tyrion anex
• 8,270 points
57 views

1 answer to this question.

0 votes

Make use of the ggplot2 package.

Start by installing and loading it into your R environment and then try this:

x <- as.data.frame(sim_fair_coin)
ggplot(x, aes(factor(sim_fair_coin))) + geom_bar(width=.5)
answered Jan 21 by Sophie may
• 9,530 points

Related Questions In Data Analytics

0 votes
1 answer

R programming: Monte Carlo Simulation

You can use the sample_n from dplyr to select ...READ MORE

answered Feb 19 in Data Analytics by Tyrion anex
• 8,270 points
109 views
0 votes
2 answers

What are the rules to define a variable name in R programming language?

The same rules almost follow for all ...READ MORE

answered Aug 26 in Data Analytics by anonymous
• 25,900 points
85 views
0 votes
1 answer

Why should I adopt R programming

R Programming is the best mechanism for ...READ MORE

answered Oct 29, 2018 in Data Analytics by Maverick
• 10,040 points
24 views
0 votes
2 answers

Error: could not find function - R Programming

Yes, Just like @Maverik said, It happens ...READ MORE

answered Aug 22 in Data Analytics by anonymous
• 25,900 points
2,567 views
0 votes
1 answer

R Programming: Implement Newton Raphson Algorithm

The problem is that the expressions for f and f1 ...READ MORE

answered Jan 7 in Data Analytics by Tyrion anex
• 8,270 points
117 views
+1 vote
2 answers
0 votes
1 answer

R programming logic

Use gsub to match the substring that we want ...READ MORE

answered Nov 16, 2018 in Data Analytics by Maverick
• 10,040 points
28 views
0 votes
1 answer
0 votes
1 answer

R Programming: matrices

Try this, It will test if a matrix ...READ MORE

answered Dec 17, 2018 in Data Analytics by Sophie may
• 9,530 points
29 views
0 votes
1 answer

R programming: Unexpected symbol error

Format your code this way: myfunction <- function() ...READ MORE

answered Dec 17, 2018 in Data Analytics by Sophie may
• 9,530 points
233 views