|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Converting qqplot2 qplot() to grammar?Hello all,
I've been using the following qplot command: qplot(pixX,pixY, data=som, geom="tile", fill=rgb) + scale_fill_identity() + opts(aspect.ratio = .75) + facet_grid(unitX ~ unitY) Now I would like to convert it into the explicit ggplot grammar, so I can remove the extras: axes, labels, background, borders, facet labels, and extra white-space around the plot. (If anyone has suggestions on removing these please let me know) I've come up with the following but it is not behaving the same way as the qplot above: ggplot(data = somdf, mapping = aes(x = pixX, y = pixY)) + layer(data = somdf, geom = "tile", fill=rgb) + scale_y_continuous(name=" ",breaks=" ") + scale_x_continuous(name=" ",breaks=" ") + scale_fill_identity() + coord_cartesian() + opts(aspect.ratio = .75) + facet_grid(unitX ~ unitY,margins=FALSE) The result is a plot where all tiles are filled with grey50, and not the data values. I've also tried this variation with the same results: ggplot(data = somdf, mapping = aes(x = pixX, y = pixY)) + geom_tile(data = somdf, fill=rgb) + scale_y_continuous(name=" ",breaks=" ") + scale_x_continuous(name=" ",breaks=" ") + scale_fill_identity() + coord_cartesian() + opts(aspect.ratio = .75) + facet_grid(unitX ~ unitY,margins=FALSE) The other issue I'm having is that the above seems to create multiple plots, another, apparently identical, plot gets drawn after I call dev.off(). I have no idea why this would be so. Setting name and breaks to " " seems like a hack to get rid of the axis stuff, is there a better way? Oh, and I can't find documentation for opts() on the ggplot2 website, where is it available? Thanks all, Hadley in particular, B. Bogart ______________________________________________ R-help@... 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. |
|
|
Re: Converting qqplot2 qplot() to grammar?On Mon, May 12, 2008 at 3:31 PM, B. Bogart <bbogart@...> wrote:
> Hello all, > > I've been using the following qplot command: > > qplot(pixX,pixY, data=som, geom="tile", fill=rgb) + > scale_fill_identity() + opts(aspect.ratio = .75) + facet_grid(unitX ~ unitY) > > Now I would like to convert it into the explicit ggplot grammar, so I > can remove the extras: axes, labels, background, borders, facet labels, > and extra white-space around the plot. (If anyone has suggestions on > removing these please let me know) You're missing one thing. You want: layer(data = somdf, geom = "tile", aes(fill=rgb)) (i.e. there's an aes function wrapped around the fill). I'd probably use a few more of the built in defaults to get: geom_tile(aes(fill = rgb)) > The other issue I'm having is that the above seems to create multiple > plots, another, apparently identical, plot gets drawn after I call > dev.off(). I have no idea why this would be so. Could you provide a fuller description of what you're trying to do? > Setting name and breaks to " " seems like a hack to get rid of the axis > stuff, is there a better way? Not at the moment. > Oh, and I can't find documentation for opts() on the ggplot2 website, > where is it available? Just in R at the moment - see ?opts. Hadley -- http://had.co.nz/ ______________________________________________ R-help@... 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. |
|
|
Re: Converting qqplot2 qplot() to grammar?Thanks Hadley,
I did not even consider needing the aes() function. It does seem to be behaving properly now. > Could you provide a fuller description of what you're trying to do? Now that this part is working there are two more aspects of the plot I would like to remove: (in order of importance) * The row/column facetting labels. * the whitespace that surrounds the plot. I'd like the ggsave output to resemble the "cropped.png" file rather than the "ggplot.png" file (attached). * the gaps between the subplots (or the ability to change the colour of the subplot border?, looks to be grey50.) > Just in R at the moment - see ?opts. Hmm, I just get the generic R help for ggplot that says go to the website for complete documentation. That's using R 2.6.2 (2008-02-08). Thanks for your help, B. Bogart hadley wickham wrote: > You're missing one thing. You want: > > layer(data = somdf, geom = "tile", aes(fill=rgb)) > > (i.e. there's an aes function wrapped around the fill). I'd probably > use a few more of the built in defaults to get: > > geom_tile(aes(fill = rgb)) > > >> The other issue I'm having is that the above seems to create multiple >> plots, another, apparently identical, plot gets drawn after I call >> dev.off(). I have no idea why this would be so. > > >> Setting name and breaks to " " seems like a hack to get rid of the axis >> stuff, is there a better way? > > Not at the moment. > >> Oh, and I can't find documentation for opts() on the ggplot2 website, >> where is it available? > > > Hadley > > ______________________________________________ R-help@... 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. |
|
|
Re: Converting qqplot2 qplot() to grammar?> Now that this part is working there are two more aspects of the plot I
> would like to remove: (in order of importance) > > * The row/column facetting labels. You should be able to find that using grid.ls() > * the whitespace that surrounds the plot. I'd like the ggsave output to > resemble the "cropped.png" file rather than the "ggplot.png" file > (attached). That's not easy to do at the moment, because you need to modify properties of the viewports, which you can't currently do with grid. I'm working on a better customisation solution that should allow you to do this. (And to package everything up into a theme that can easily be applied to other plots) > * the gaps between the subplots (or the ability to change the colour of > the subplot border?, looks to be grey50.) As above. > Hmm, I just get the generic R help for ggplot that says go to the > website for complete documentation. That's weird - you might need to upgrade your R to get the latest version of ggplot2. Hadley -- http://had.co.nz/ ______________________________________________ R-help@... 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. |
| Free Forum Powered by Nabble | Forum Help |