Bar chart with unstable rug

Next 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 nice picture:

Bar graph with rug

But many of these blue lines overlap. I would like to add a little shake! I tried using:

 p<-p+geom_rug(sides="b", position="jitter", colour="blue") 

But I got an error message:

stat_bin: binwidth The default is range / 30. Use "binwidth = x" to configure this. Error: position_jitter requires the following missing aesthetic properties: y

The y coordinate for the histogram is the count that the histogram should automatically do.

How can I get my inconvenience?

+5
source share
1 answer

You can just give y of 0 in the aes call, and it will display everything in order:

 p + geom_rug(sides = "b", aes(y = 0), position = "jitter", colour = "blue") 

using more obvious data:

 dat <- c(rep(1, 50), rep(2, 50)) dat <- data.frame(dat) 

without jitter:

enter image description here

With jitter:

enter image description here

+6
source

All Articles