Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require(ggplot2)
- delta <- 0.0001 #smaller for smoother curves but longer plot times
- chisq.df <- data.frame(x = seq(from=0.01, to=5, by=delta)) #avoid near 0 due to spike in pdf
- chisq.df$pdf <- dchisq(chisq.df$x, df=1)
- chisq.df$decile <- floor(10*pchisq(chisq.df$x, df=1) + 1)
- g <- ggplot(chisq.df, aes(x=x, y=pdf, fill=decile)) + scale_fill_gradient2(midpoint=5.5, guide="none") + theme_bw()
- for(n in 1:10) g <- g + geom_ribbon(data=subset(chisq.df, decile == n), aes(ymin=0, ymax=pdf), colour = "black")
- print(g)
- z.df <- data.frame(x = seq(from=-3, to=3, by=delta))
- z.df$pdf <- dnorm(z.df$x)
- z.df$decile <- floor(10*pnorm(z.df$x) + 1)
- g <- ggplot(z.df, aes(x=x, y=pdf, fill=decile)) + scale_fill_gradient2(midpoint=5.5, guide="none") + theme_bw() +xlab("y")
- for(n in 1:10) g <- g + geom_ribbon(data=z.df[z.df$decile == n,], aes(ymin=0, ymax=pdf), colour = "black")
- print(g)
- data.df <- data.frame(x=c(seq(from=0, to=6, by=delta)))
- data.df$y <- qnorm(pchisq(data.df$x, df=1))
- ggplot(data.df, aes(x,y)) + theme_bw() + geom_line()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement