Brian Tsai
2010-Aug-12 03:14 UTC
[R] drawing dot plots with size, shape affecting dot characteristics
Hi all, I'm interested in doing a dot plot where *both* the size and color (more specifically, shade of grey) change with the associated value. I've found examples online for ggplot2 where you can scale the size of the dot with a value: http://had.co.nz/ggplot2/graphics/6a053f23cf5bdfe5155ab53d345a5e0b.png Or scale the color with the value: http://had.co.nz/ggplot2/graphics/b17bf93530ff6695afb366e65677c17f.png both of which are from here: http://had.co.nz/ggplot2/geom_point.html but I've been playing around with ggplot2 and couldn't figure out how to do both at the same time - ideally i want size to increase with a value, and the shade of grey to get lighter with increasing value. Any help's appreciated, thanks! Brian [[alternative HTML version deleted]]
Michael Bedward
2010-Aug-12 06:32 UTC
[R] drawing dot plots with size, shape affecting dot characteristics
Try running this and see if it does what you want. It just uses plain old plot with the cex arg for size and the col arg for colour... greyDots <- function() { # make up some data x <- runif(50, 0, 10) y <- runif(50, 0, 10) valueMax <- 100 value <- sample(valueMax, 50) # edit these to taste maxDotSize <- 5 maxGreyLevel <- 0.8 plot(x, y, pch=16, xlim=c(0,10), ylim=c(0,10), cex=maxDotSize * value / valueMax, col=grey(maxGreyLevel * value / valueMax)) } On 12 August 2010 13:14, Brian Tsai <btsai00 at gmail.com> wrote:> Hi all, > > I'm interested in doing a dot plot where *both* the size and color (more > specifically, shade of grey) change with the associated value.
Hadley Wickham
2010-Aug-12 18:27 UTC
[R] drawing dot plots with size, shape affecting dot characteristics
On Wed, Aug 11, 2010 at 10:14 PM, Brian Tsai <btsai00 at gmail.com> wrote:> Hi all, > > I'm interested in doing a dot plot where *both* the size and color (more > specifically, shade of grey) change with the associated value. > > I've found examples online for ggplot2 where you can scale the size of the > dot with a value: > > http://had.co.nz/ggplot2/graphics/6a053f23cf5bdfe5155ab53d345a5e0b.png > > Or scale the color with the value: > > http://had.co.nz/ggplot2/graphics/b17bf93530ff6695afb366e65677c17f.png > > both of which are from here: > http://had.co.nz/ggplot2/geom_point.html > > but I've been playing around with ggplot2 and couldn't figure out how to do > both at the same time - ideally i want size to increase with a value, and > the shade of grey to get lighter with increasing value.qplot(mpg, wt, data = mtcars, colour = qsec, size = qsec) + scale_colour_grey() Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/