Re: [R] ggplot bar geom: control the filling in the colour legend
Hi On 13/09/2010 8:03 p.m., Benoit Boulinguiez wrote: Hi all, I'm still seeking for tweaking the appearance of the color legend in a bar goemetry with ggplot2. I can't seem to control the filling of the colour legend squares take this, ggplot(diamonds, aes(clarity, fill=color,colour = cut)) + geom_bar(position = dodge) and I'd need a white filling in the colour legend, instead of the black one. I couldn't see a theme element that would allow you to modify that via opts(), but you could go lower-level and edit the appropriate rect grobs. Having produced the plot ... ggplot(diamonds, aes(clarity, fill=color,colour = cut)) + geom_bar(position = dodge) ... you could inspect grid.ls() output by eye to see which grobs these are likely to be and do something like ... grid.gedit(gPath(GRID.cellGrob.439, legend.frame, GRID.cellGrob, key.gTree, GRID.rect), gp=gpar(fill=white)) ... but the 439 will change each time you produce the plot (it will almost certainly be a different number for you) so could automate somewhat by using grid.ls() to determine the *second* GRID.cellgrob directly beneath the legends grob ... grobList - grid.ls() secondLegend - grep(legends::GRID.cellGrob.[0-9]+$, grobList$gPath)[2] grobName - grobList$name[secondLegend - 1] grid.gedit(gPath(grobName, legend.frame, GRID.cellGrob, key.gTree, GRID.rect), gp=gpar(fill=white)) ... which should work (for your plot) every time you draw it. Is that the result you were after? Paul Does anyone know how to rule that? All the best Le 11/09/2010 10:27, Benoit Boulinguiez a écrit : Sorry my bad, example too simple try that one out. ggplot(diamonds, aes(clarity, fill=color,colour = cut)) + geom_bar(position = dodge) I want change the filling in the colour legend, not the filling of the bars. Regards Le 10/09/2010 20:41, Ista Zahn a écrit : ggplot(diamonds, aes(clarity, colour = cut)) + geom_bar(fill=white) __ R-help@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. __ R-help@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. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ __ R-help@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.
[R] ggplot bar geom: control the filling in the colour legend
Hi all, I'm still seeking for tweaking the appearance of the color legend in a bar goemetry with ggplot2. I can't seem to control the filling of the colour legend squares take this, ggplot(diamonds, aes(clarity, fill=color,colour = cut)) + geom_bar(position = dodge) and I'd need a white filling in the colour legend, instead of the black one. Does anyone know how to rule that? All the best Le 11/09/2010 10:27, Benoit Boulinguiez a écrit : Sorry my bad, example too simple try that one out. ggplot(diamonds, aes(clarity, fill=color,colour = cut)) + geom_bar(position = dodge) I want change the filling in the colour legend, not the filling of the bars. Regards Le 10/09/2010 20:41, Ista Zahn a écrit : ggplot(diamonds, aes(clarity, colour = cut)) + geom_bar(fill=white) __ R-help@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. __ R-help@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.
Re: [R] ggplot bar geom: control the filling in the colour legend
Sorry my bad, example too simple try that one out. ggplot(diamonds, aes(clarity, fill=color,colour = cut)) + geom_bar(position = dodge) I want change the filling in the colour legend, not the filling of the bars. Regards Le 10/09/2010 20:41, Ista Zahn a écrit : ggplot(diamonds, aes(clarity, colour = cut)) + geom_bar(fill=white) __ R-help@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.
[R] ggplot bar geom: control the filling in the colour legend
Hi all, Is it possible to change the filling of the squares used to represent the colour legend in a bar plot with ggplot? in this example, fillings are raven black, I'd like them white. ggplot(diamonds, aes(clarity, colour = cut)) + geom_bar() Regards -- - Benoit Boulinguiez Ph.D student Ecole de Chimie de Rennes (ENSCR) Bureau 1.20 Equipe CIP UMR CNRS 6226 Sciences Chimiques de Rennes Avenue du Général Leclerc CS 50837 35708 Rennes CEDEX 7 Tel 33 (0)2 23 23 80 83 Fax 33 (0)2 23 23 81 20 http://www.ensc-rennes.fr/ __ R-help@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.
Re: [R] ggplot bar geom: control the filling in the colour legend
Sure, just change the color of the fill. ggplot(diamonds, aes(clarity, colour = cut)) + geom_bar(fill=white) -Ista On Fri, Sep 10, 2010 at 2:24 PM, Benoit Boulinguiez benoit.boulingu...@ensc-rennes.fr wrote: Hi all, Is it possible to change the filling of the squares used to represent the colour legend in a bar plot with ggplot? in this example, fillings are raven black, I'd like them white. ggplot(diamonds, aes(clarity, colour = cut)) + geom_bar() Regards -- - Benoit Boulinguiez Ph.D student Ecole de Chimie de Rennes (ENSCR) Bureau 1.20 Equipe CIP UMR CNRS 6226 Sciences Chimiques de Rennes Avenue du Général Leclerc CS 50837 35708 Rennes CEDEX 7 Tel 33 (0)2 23 23 80 83 Fax 33 (0)2 23 23 81 20 http://www.ensc-rennes.fr/ __ R-help@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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@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.
Re: [R] ggplot bar geom: control the filling in the colour legend
Hi: On Fri, Sep 10, 2010 at 11:24 AM, Benoit Boulinguiez benoit.boulingu...@ensc-rennes.fr wrote: Hi all, Is it possible to change the filling of the squares used to represent the colour legend in a bar plot with ggplot? in this example, fillings are raven black, I'd like them white. Ista answered the question you posed, but let's try some alternatives - I'm not saying they're any better, but it gives you more options. # library(ggplot2) # Using the diamonds data set, part of the ggplot2 package. # Reference plot (from Ista): ggplot(diamonds, aes(clarity, colour = cut)) + geom_bar(fill=white) # Change the background fill color: last_plot() + opts(panel.background = theme_rect(fill = 'lavender')) + opts(panel.grid.major = theme_blank(), panel.grid.minor = theme_blank()) # Change the fill color: ggplot(diamonds, aes(clarity, fill = cut)) + geom_bar() # Change the outline color to white: ggplot(diamonds, aes(clarity, fill = cut)) + geom_bar(colour = 'white') HTH, Dennis ggplot(diamonds, aes(clarity, colour = cut)) + geom_bar() Regards -- - Benoit Boulinguiez Ph.D student Ecole de Chimie de Rennes (ENSCR) Bureau 1.20 Equipe CIP UMR CNRS 6226 Sciences Chimiques de Rennes Avenue du Général Leclerc CS 50837 35708 Rennes CEDEX 7 Tel 33 (0)2 23 23 80 83 Fax 33 (0)2 23 23 81 20 http://www.ensc-rennes.fr/ __ R-help@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. [[alternative HTML version deleted]] __ R-help@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.