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

Keith Ponting k.ponting at aurix.com
Fri Oct 10 13:17:18 CEST 2008


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



More information about the R-help mailing list