This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
movies <- movies[1:1000,] | |
m <- ggplot(movies, aes(x=rating)) | |
m + geom_histogram(binwidth=0.2, colour = "darkgreen", fill = "white", size=1) + geom_point(aes(y = -2), position = position_jitter(height = 0.8), size=1) |
Alternatively, using the geom_rug function:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
movies <- movies[1:1000,] | |
m <- ggplot(movies, aes(x=rating)) | |
m + geom_histogram(binwidth=0.2, colour = "darkgreen", fill = "white", size=1) + geom_rug(aes(y=-2), position="jitter", sides="b") |
Of course this simplicistic method need to be adjusted in vertical position of the stripchart or rugchart (y=-2, here), and the relative proportion of points jittering.
can you also overlay a normal curve over the histograms, please
ReplyDeleteI'm a fan of ggplot2 and I like this post! So thank you!
ReplyDelete@Duleep Samuel : to easily overlay normal curve over histograms, you can use easyGgplot2 package. See this article : http://www.sthda.com/english/wiki/ggplot2-histogram-easy-histogram-graph-with-ggplot2-r-package