require(ggplot2) require(plyr) # nth row of Pascal's T. # scaled to the xy units of Std. Gaussian df <- function(n){ if (n < 20) k <- 0:n else k <- round(n/2-2*sqrt(n)):round(n/2+2*sqrt(n)) x <- (2*k-n)/sqrt(n) if (n < 1000) y <- sqrt(n)*choose(n,k)/2^(n+1) else y <- dnorm(x) data.frame(n=n,k=k,x=x,y=y) } nlist <- c(2,4,6,100,800,10000) DF <- ldply(nlist,df) p <- ggplot(DF,aes(x,y,col=factor(n),size=20/sqrt(n)))+geom_point()+xlim(-4,4) xL <- expression(paste("Standard Units ",frac(2,sqrt(n))(k-n/2))) yL <- expression(paste("Density of Probability: ", frac(C(n,k),2^n) / frac(2,sqrt(n)))) q <- p+xlab(xL)+ylab(yL)+labs(col="n")+ ggtitle("Pascal's Triangle Approach to the Bell Curve")+ scale_size_area(max_size=10,guide=FALSE) q # pascal's T. df1 <- function(n){ k <- 0:n cnk <- choose(n,k) data.frame(n=n,k=k,cnk=cnk,x=k-n/2,y=-n/(n+10)) } nlist <- 0:4 DF1 <- ldply(nlist,df1) p1 <- ggplot(DF1,aes(x=x,y=y,col=factor(n),size=10/(1+n)))+ geom_text(aes(label=cnk))+ scale_x_continuous(breaks=NULL)+ scale_y_continuous(breaks=NULL)+ labs(x=NULL,y=NULL)+ scale_size(range=c(4,10))+ guides(col=FALSE,size=FALSE)+ theme(plot.background = element_rect(colour = "#FDFDFD", fill = "#E6E6E6")) p1 # main plot + pascal's T in corner g <- ggplotGrob(p1) q+annotation_custom(grob=g,xmin=2,xmax=4,ymin=0.3,ymax=0.4)