Skip to content

help with gradient boxplot

7 messages · Fix Ace, Paul Murrell

#
Hello, there,
I will like to fill the boxplot with gradient color, as exampled below:

Can anyone help me figure out what package I should go with?
Thank you very much for any inputs!
Kind regards,
Ace
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 72026 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20161206/27d24464/attachment.png>
#
Hi

'gridSVG' might be one way to get this.  For example ...

library(lattice)
# Draw boxplot (with a package that sits on top of 'grid')
bwplot(voice.part ~ height, data=singer, xlab="Height (inches)",
        horizontal=FALSE)

library(grid)
grid.ls()
# Looks like boxes are called <blah>bwplot.box.polygon<blah>

library(gridSVG)
# Define linear gradient
fill <- linearGradient(c("blue", "red"),
                        x0=.5, x1=.5,
                        gradientUnits="coords")
# Register gradient now so it applies to the whole page
registerGradientFill("br", fill)
# Fill each box with gradient
grid.gradientFill("bwplot.box.polygon", label=rep("br", 17), grep=TRUE,
                   group=FALSE)
# Generate SVG version "Rplots.svg"
# (where the gradient will actually be visible)
grid.export()

Does that help ?

Paul
On 07/12/16 09:14, Fix Ace wrote:

  
    
1 day later
#
Hi, Paul,
Thank you very much for your reply. I tried your sample code, but did not get gradient filling (still empty box). And many warnings:1: In checkAttrs(attrs, eltName) :
? Removing non-SVG attribute name(s): fill, fill-opacity
2: In checkAttrs(attrs, eltName) :
? Removing non-SVG attribute name(s): fill, fill-opacity
3: In checkAttrs(attrs, eltName) :
? Removing non-SVG attribute name(s): fill, fill-opacity
4: In checkAttrs(attrs, eltName) :
? Removing non-SVG attribute name(s): fill, fill-opacity
5: In checkAttrs(attrs, eltName) :
...

I saw the figure in an article, and so I don't have to script. I am actually trying to generate the similar figure for my own data. 

Any other thoughts?
Thanks.
Ace
On Tuesday, December 6, 2016 7:43 PM, Paul Murrell <paul at stat.auckland.ac.nz> wrote:
Hi

'gridSVG' might be one way to get this.? For example ...

library(lattice)
# Draw boxplot (with a package that sits on top of 'grid')
bwplot(voice.part ~ height, data=singer, xlab="Height (inches)",
? ? ? ? horizontal=FALSE)

library(grid)
grid.ls()
# Looks like boxes are called <blah>bwplot.box.polygon<blah>

library(gridSVG)
# Define linear gradient
fill <- linearGradient(c("blue", "red"),
? ? ? ? ? ? ? ? ? ? ? ? x0=.5, x1=.5,
? ? ? ? ? ? ? ? ? ? ? ? gradientUnits="coords")
# Register gradient now so it applies to the whole page
registerGradientFill("br", fill)
# Fill each box with gradient
grid.gradientFill("bwplot.box.polygon", label=rep("br", 17), grep=TRUE,
? ? ? ? ? ? ? ? ? group=FALSE)
# Generate SVG version "Rplots.svg"
# (where the gradient will actually be visible)
grid.export()

Does that help ?

Paul
On 07/12/16 09:14, Fix Ace wrote:

  
    
#
Hi

You could try ...

grid.export(..., strict=FALSE)

... and/or install the latest gridSVG version from R-Forge ...

https://r-forge.r-project.org/R/?group_id=1025

Paul
On 09/12/16 11:13, Fix Ace wrote:

  
    
#
Hi, Paul,
Thank you very much! It works this time with "strict=FALSE" option.
Another relevant question:
how did you figure out? that boxes in boxplot are called "bwplot.box.polygon". If I am trying to make a gradient filling for barplot of other plots, how would I define grobs?
Thanks!!
Ace
On Thursday, December 8, 2016 5:24 PM, Paul Murrell <paul at stat.auckland.ac.nz> wrote:
Hi

You could try ...

grid.export(..., strict=FALSE)

... and/or install the latest gridSVG version from R-Forge ...

https://r-forge.r-project.org/R/?group_id=1025

Paul
1 day later
#
Hi

Great to hear you have it working.

Figuring out the names of grobs takes two things:

1. someone has to name the grobs
2. grid.ls()

The reason why I did my example using 'lattice' is because 'lattice' 
names all of its grobs.  There is a document ...

http://lattice.r-forge.r-project.org/Vignettes/src/naming-scheme/namingScheme.pdf

... that describes the 'lattice' naming scheme.

Paul
On 10/12/16 10:39, Fix Ace wrote:

  
    
#
Hi, Paul,
Thank you so much for this further clarification!
Ace
On Sunday, December 11, 2016 2:09 PM, Paul Murrell <paul at stat.auckland.ac.nz> wrote:
Hi

Great to hear you have it working.

Figuring out the names of grobs takes two things:

1. someone has to name the grobs
2. grid.ls()

The reason why I did my example using 'lattice' is because 'lattice' 
names all of its grobs.? There is a document ...

http://lattice.r-forge.r-project.org/Vignettes/src/naming-scheme/namingScheme.pdf

... that describes the 'lattice' naming scheme.

Paul
On 10/12/16 10:39, Fix Ace wrote: