Raj Minhas
2008-Aug-25 18:15 UTC
[R] ggplot scale_size - is there any way to specify breaks?
Hi, I am plotting scores for students in a school using a command of the form qplot(x=Subject, y=Student, data=dataset, geom="point", size=Score) It lists the Subject factors on the x-axis and the Student factors on the y-axis - dots proportional to the Score are plotted at the resultant grid. It works just as I want. However, I want to plot a number of these graphs (eg. datasets from different grades or school years) and want to keep the dot sizes consistent across the various graphs. The default behavior of scale_size() seems to be to train on the given dataset so if the range of scores is different for different datasets then the dot sizes can be inconsistent. For example, assume that the scores for the various subjects can range from 1 to 4. Typically, the scores will have span the entire range but it is not guaranteed. If none of the students in a grade have a score lower than 2 on any of the subjects then the smallest dot size for this grade will correspond to a score of 2 whereas the same dot size will correspond to a score of 1 for the other grades. Is there any way to specify a range to scale_size()? There is an option called "breaks" in scale_size_identity() that does what I want. Is there something similar for scale_size()? Thanks. -Raj. -- View this message in context: http://www.nabble.com/ggplot-scale_size---is-there-any-way-to-specify-breaks--tp19148944p19148944.html Sent from the R help mailing list archive at Nabble.com.
hadley wickham
2008-Aug-25 18:52 UTC
[R] ggplot scale_size - is there any way to specify breaks?
> Is there any way to specify a range to scale_size()? There is an option > called "breaks" in scale_size_identity() that does what I want. Is there > something similar for scale_size()?Not in the released version, but there is in the development version - all scales now take a limits argument which lets you set the limits independently of the data. I'm hoping to release the next version in the next couple of months. Until then, you could do something like: dummy <- data.frame(Score = range(dataset$Score)) qplot(...) + geom_point(aes(x=1, y=1), data=dummy, colour = NA) This adds a layer with two invisible points that force the size scale to expand to the maximum extend needed. Hadley> > Thanks. > > -Raj. > -- > View this message in context: http://www.nabble.com/ggplot-scale_size---is-there-any-way-to-specify-breaks--tp19148944p19148944.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- http://had.co.nz/