The following script
library(ggplot2)
dat<-rnorm(80)
dat<-data.frame(dat)
p<-ggplot(dat, aes(x=dat))+geom_histogram()
p<-p+geom_rug(sides="b", colour="blue")
p
makes this pretty picture:
But many of those blue lines overlap. I'd like to add some jitter! I've tried using:
p<-p+geom_rug(sides="b", position="jitter", colour="blue")
But I'm given an error message:
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this. Error: position_jitter requires the following missing aesthetics: y
The y
coordinate for a histogram is the count, which the histogram should make automagically.
How can I get my jitters?
A rug plot is a plot of data for a single quantitative variable, displayed as marks along an axis. It is used to visualise the distribution of the data. As such it is analogous to a histogram with zero-width bins, or a one-dimensional scatter plot.
ticksize. The length of the ticks making up the 'rug'. Positive lengths give inwards ticks. side. On which side of the plot box the rug will be plotted.
geom_rug.Rd. A rug plot is a compact visualisation designed to supplement a 2d display with the two 1d marginal distributions. Rug plots display individual cases so are best used with smaller datasets.
MatplotlibPythonData Visualization. Rug plots are used to visualize the distribution of data. It is a plot of data for a single variable, displayed as marks along an axis. To make a rug plot in Matplotlib, we can take the following steps − Set the figure size and adjust the padding between and around the subplots.
You can simply give a y of 0 in an aes
call, and it will plot everything ok:
p + geom_rug(sides = "b", aes(y = 0), position = "jitter", colour = "blue")
using some more obvious data:
dat <- c(rep(1, 50), rep(2, 50))
dat <- data.frame(dat)
without jitter:
With jitter:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With