geom_density + geom_rug with position=jitter, v0.9.3

892 views
Skip to first unread message

Gad Abraham

unread,
Dec 12, 2012, 6:49:25 PM12/12/12
to ggp...@googlegroups.com
Hi,

I'm trying to jitter the rug in a density plot, but can't get it going, where do I need to specify y:

> library(ggplot2)
> d <- data.frame(x=rnorm(100), y=factor(sample(0:1, 100, replace=TRUE)))
> ggplot(d, aes(x, colour=y)) + geom_density() + geom_rug() # works fine
> ggplot(d, aes(x, colour=y)) + geom_density() + geom_rug(position="jitter")
Error: position_jitter requires the following missing aesthetics: y

Thanks,
Gad

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

other attached packages:
[1] ggplot2_0.9.3

loaded via a namespace (and not attached):
 [1] colorspace_1.2-0   dichromat_1.2-4    digest_0.6.0       grid_2.15.2        gtable_0.1.2       labeling_0.1       MASS_7.3-22        munsell_0.4      
 [9] plyr_1.8           proto_0.3-9.2      RColorBrewer_1.0-5 reshape2_1.2.2     scales_0.2.3       stringr_0.6.2      tools_2.15.2     

Winston Chang

unread,
Dec 12, 2012, 9:21:27 PM12/12/12
to Gad Abraham, ggplot2
You could do something like this:

library(ggplot2)
d <- data.frame(x=rnorm(100), y=factor(sample(0:1, 100, replace=TRUE)))

ggplot(d, aes(x, colour=y)) + geom_density() +
  geom_rug(aes(y=y), position="jitter", sides="b")

The y position isn't actually used, but it will make position_jitter happy.



--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Gad Abraham

unread,
Dec 12, 2012, 9:56:05 PM12/12/12
to Winston Chang, ggplot2
Great, thanks Winston.
Reply all
Reply to author
Forward
0 new messages