How to draw bar plots for multiple conditions?

Hello every one,

I am new to R studio and I am trying to draw bar plots for a specific problem, which has multiple conditions. the problem is:

A producer guarantees that germinability of one special pea cultivar is 50%. A gardener bought 50 pea seeds.
Calculate the probability that:

  1. all seeds will sprout,
  2. at most 5 seeds will sprout,
  3. at least 4 seeds will sprout.
  4. and so on...

Now, how can I draw bar plots for these? I am currently having this solution:

xP50 <- c(0:50)
prob1 <- dbinom(xP50,50,0.5)
tab1 <- data.frame(value = xP50, probability = prob1)
barplot(tab1$probability)

and for the second one, I have:

xP5 <- c(0:50)
prob2 <- dbinom(xP5,50,0.5)
tab2 <- data.frame(value = xP5, probability = prob2)
barplot(tab2$probability)

Is this the right way, to achieve the bar plots? Am I doing it correctly?

Thank You.

Hi muggy,

This might not answer your specific question directly, but you may find the following documentations very helpful if you're new to R.

This is the website for “R for Data Science” . This book will teach you how to do data science with R: You’ll learn how to get your data into R, get it into the most useful structure, transform it, visualise it and model it. In this book, you will find a practicum of skills for data science.

And a bit more specifically regarding creating visualisations:

This chapter will teach you how to visualise your data using ggplot2. R has several systems for making graphs, but ggplot2 is one of the most elegant and most versatile. ggplot2 implements the grammar of graphics , a coherent system for describing and building graphs. With ggplot2, you can do more faster by learning one system and applying it in many places.

There are even more excellent online books available, to start with:

Hope this helps you in general a bit forward.

1 Like

aside from the object names which differ, the calculations performed here are identical, which is probably a mistake

1 Like

Thank you for the response. Can you please tell me how should I re-write that? and where are the mistakes? did not I answered the first and second questions in my code?

I am new to R. Thank you :pray:

Yes, the second one is typed mistakenly. it is xP5 <- c(0:5)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.