[R] histogram loses top row with alpha transparency under Windows

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Oct 14 13:09:23 CEST 2008


I *presume* this is the windows() device in a current version of R, but 
you failed to tell us almost any of the information requested in the 
posting guide.

If so, you are seeing how Windows GDI copying operations work: if the 
region to be copied goes off-window, they clip the region completely. Your 
example works in R-devel, and if that survives a few weeks of testing, I 
might port the workaround to 2.8.1.  (A similar fix in 2.7.1 patched ended 
up with undesirable side effects in 2.7.2, so careful testing is needed.)

Implementing semi-transparent colours on windows() was hard, and it would 
be nice to see some appreciation of the effort involved.

On Fri, 10 Oct 2008, Keith Ponting wrote:

> Richard.Cotton wrote:
>
>> The rectangles being drawn extend higher than the top of the panel.
> (Your y
>> axis ranges from 0 to 50, but the bars go up to 100.)
>>
>
> Thankyou - I can also make the bars on the lower panels vanish by
> tinkering with ylim.
>
>> In the top row of plots, depending upon the shape of your device
> window, the
>> bars can extend beyond the range of the device window.  For some
> reason,
>> (take a look in panel.rect), when you specify alpha less than 1, this
>> prevents the bar being drawn.
>
> The problem lies deeper. I can demonstrate the same effect with raw grid
> calls (but cannot find a way into "grid.draw" to see what is going on):
>
> cols <- rainbow(2,alpha=0.5)
> library(grid)
> grid.newpage()
> pushViewport(plotViewport(c(5,4,2,2)))
> # draw viewport limits:
> grid.rect()
> # VISIBLE: small projection outside viewport, transparent fill and edge
> grid.rect(gp=gpar(fill=cols[2],col=cols[1]),height=unit(1.1,"npc"),width
> =unit(0.18,"npc"),x=0.1)
> # VISIBLE: small projection outside viewport, standard colours fill and
> edge
> grid.rect(gp=gpar(fill=2,col=3),height=unit(1.1,"npc"),width=unit(0.18,"
> npc"),x=0.3)
> # INVISIBLE: larger projection outside viewport, transparent colours
> fill and edge
> grid.rect(gp=gpar(fill=cols[2],col=cols[1]),height=unit(1.5,"npc"),width
> =unit(0.18,"npc"),x=0.5)
> # VISIBLE: larger projection outside viewport, standard colours fill and
> edge
> grid.rect(gp=gpar(fill=2,col=3),height=unit(1.5,"npc"),width=unit(0.18,"
> npc"),x=0.7)
> # MIXED: larger projection outside viewport, standard colour edge
> visible, transparent fill not
> grid.rect(gp=gpar(fill=cols[2],col=3),height=unit(1.5,"npc"),width=unit(
> 0.18,"npc"),x=0.9)
>
> I can also show the same effect using standard graphics calls:
>
> par(xpd=NA)
> plot(c(1,2))
> rect(1.01,1,1.19,2.2,border=cols[1],col=cols[2])
> rect(1.21,1,1.39,2.2,border=3,col=2)
> rect(1.41,1,1.59,4,border=cols[1],col=cols[2])
> rect(1.61,1,1.79,4,border=3,col=2)
> rect(1.81,1,1.99,4,border=3,col=cols[2])
>
> Both of these examples have missing alpha transparency colours under
> Windows but produce the expected filled rectangles under Linux.
>
>>
>> You need to add type="count" to the call to histogram, or rescale the
> bar
>> heights.
>
> My post was a rather simplified example - I am actually trying to make
> visible a "small" distribution on the skirt of a large one, which means
> that scaling the bar heights is not sufficient. I have worked around the
> problem by modifying panel.histogram to _clip_ the bar heights.
>
> Keith
>
> Keith Ponting
> Aurix Ltd, Malvern WR14 3SZ  UK
>
> ______________________________________________
> 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.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list