Skip to content

Instantly share code, notes, and snippets.

@t-student
Last active November 8, 2015 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t-student/444aa6db20f3748c2b1f to your computer and use it in GitHub Desktop.
Save t-student/444aa6db20f3748c2b1f to your computer and use it in GitHub Desktop.
# > head(df2)
# id variable cartvol time timeb
# 1 1 cartvol0 1.987862 0 0
# 2 2 cartvol0 1.694808 0 0
# 3 3 cartvol0 2.342389 0 0
# 4 4 cartvol0 1.727150 0 0
# 5 5 cartvol0 1.546601 0 0
# 6 6 cartvol0 1.425992 0 0
grid <- with(df2, seq(min(cartvol), max(cartvol), length = 100))
normaldens <- ddply(df2, .(time), function(df) {
data.frame(
predicted = grid,
density = dnorm(grid, mean(df$cartvol), sd(df$cartvol))
)
})
p <- ggplot(data = df2, aes(x=cartvol))
p <- p + geom_histogram(aes(y=..density..), binwidth=.3, colour="black", fill="white")
#p <- p + geom_density(alpha=.2, fill="#FF6666")
p <- p + geom_line(aes(x = predicted, y = density), data = normaldens, colour = "red")
p <- p + xlab("Cartilage volume")
p <- p + ylab("Probability")
p <- p + theme_bw()
p <- p + theme(legend.position="bottom")
p <- p + facet_grid(.~time)
print(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment