2016-10-29 43 views
1

我该如何去制作一个带有不同方式的两个二项式pdf的图形,并用阴影或任何其他方式填充重叠?2 R中的二项分布重叠

+0

见http://www.cookbook-r.com/Graphs/Plotting_distributions_(ggplot2)/#histogram-and -density-plots-with-multiple-group – Bernhard

+0

我不知道你的意思是“二项分布图”,但也许这是你想要的? http://stackoverflow.com/questions/6957549/overlaying-histograms-with-ggplot2-in-r –

回答

1

试试这个:

df <- rbind(data.frame(binom=rbinom(1000, 20, 0.2), binomial.p='0.2') , data.frame(binom=rbinom(1000, 20, 0.5),binomial.p='0.5')) 
library(ggplot2) 
ggplot(df, aes(binom, fill=binomial.p)) + 
geom_histogram(position = 'dodge', binwidth = 1) + 
xlab('Number of success (n=20)') 

enter image description here

ggplot(df, aes(binom, fill=binomial.p)) + 
geom_density(alpha=0.2) + 
xlab('Number of success (n=20)') 

enter image description here