[英]How to draw plots for multiple conditions in R?
I am new to R studio and I am trying to draw bar plots for a specific problem, which has multiple conditions.我是 R 工作室的新手,我正在尝试为具有多个条件的特定问题绘制条形图。 the problem is:
问题是:
A producer guarantees that germinability of one special pea cultivar is 50%.生产者保证一个特殊豌豆品种的发芽率为50%。 A gardener bought 50 pea seeds.
一位园丁买了 50 颗豌豆种子。 Calculate the probability that:
计算以下概率:
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.谢谢你。
prob=dbinom(50, 50, .5)
barplot(c(prob, 1-prob), names.arg=c("Sprout", "Not Sprout"), main="All 50 Seeds")
prob=pbinom(5, 50, .5)
barplot(c(prob, 1-prob), names.arg=c("Sprout", "Not Sprout"), main="At Most 5 Seeds")
prob=pbinom(3, 50, .5, lower.tail=FALSE)
barplot(c(prob, 1-prob), names.arg=c("Sprout", "Not Sprout"), main="At Least 4 Seeds")
xP50 <- c(0:50)
prob1 <- dbinom(xP50,50,0.5)
tab1 <- data.frame(x = xP50, probability = prob1)
library(ggplot2)
ggplot(tab1) + geom_histogram(aes(x, probability), stat="identity") + ggtitle("Probability of x pea seeds being germinable")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.