【发布时间】:2010-08-20 10:25:50
【问题描述】:
我正在尝试使用 ggplot2 生成一些示例图形,我选择的示例之一是 birthday problem,这里使用的代码“借用”自 Oscon 的革命 computing presentation。
birthday<-function(n){
ntests<-1000
pop<-1:365
anydup<-function(i){
any(duplicated(sample(pop,n,replace=TRUE)))
}
sum(sapply(seq(ntests), anydup))/ntests
}
x<-data.frame(x=rep(1:100, each=5))
x<-ddply(x, .(x), function(df) {return(data.frame(x=df$x, prob=birthday(df$x)))})
birthdayplot<-ggplot(x, aes(x, prob))+
geom_point()+geom_smooth()+
theme_bw()+
opts(title = "Probability that at least two people share a birthday in a random group")+
labs(x="Size of Group", y="Probability")
这里我的图表是我将其描述为指数的,但 geom_smooth 并不特别适合数据。我试过黄土方法,但这并没有改变太多。谁能建议如何添加更好的平滑度?
谢谢
保罗。
【问题讨论】: