ggPlot2: Histogram with jittered stripchart

[This article was first published on Statistic on aiR, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Here is an example of a Histogram plot, with a stripchart (vertically jittered) along the x side of the plot.

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)
view raw Hist1 hosted with ❤ by GitHub




Alternatively, using the geom_rug function:

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")
view raw hist2 hosted with ❤ by GitHub



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.

To leave a comment for the author, please follow the link and comment on their blog: Statistic on aiR.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)