[R] Unwanted white borders on semi-transparent polygons?

Matthew Neilson matt at gneilson.plus.com
Fri Apr 27 05:58:23 CEST 2007


Hey all,

I'm trying to create a plot of two semi-transparent regions. The reason they need to be partially transparent is so that I can see if there's any overlap. Here's some example code:

# BEGIN

pdf(file="test.pdf",version="1.4")
plot(0,0,type="l",ylim=range(-3,3),xlim=range(-1,5))
polygon(c(0,1,2,3,4,3,2,1,0), c(0,1,2,1,0,-1,-2,-1,0), col=rgb(1,0,0,0.5),
border=NA)
polygon(c(1,2,3,4,5,4,3,2,1), c(0,1,2,1,0,-1,-2,-1,0), col=rgb(0,0,1,0.5),
border=NA)
dev.off()

# END

The problem with this is that, despite setting "border = NA", I get a big white border surrounding each polygon!! Funnily enough, setting the alpha channel equal to 1 (as opposed to 
0.5) *doesn't* give the border, but an alpha channel of 1 produces an opaque polygon! :S

I have read the FAQ, and (unfortunately) turning off line-art smoothing does not give the desired effect. Furthermore, my pdfs print with a white border surrounding each transparent 
polygon.

Now, here comes the really bizarre part. Whilst Adobe Acrobat displays the unwanted white border, Apple Preview respects the "border=NA" argument and shows the two diamonds as 
they are intended. However, opening up the pdf in Illustrator CS reveals that there is in fact a transparent (according to Illustrator) border *on top* of each diamond. Deleting these 
two borders (one for each polygon) and re-saving the pdf appears to correct the issue. So the obvious question is: how did the surrounding borders get there in the first place? A bug 
in the polygon function, perhaps?

Does anyone have any ideas for preventing these unwanted borders around semi-transparent polygons (without having to resort to Illustrator)? Has anyone else even come across this 
problem?

Many thanks,


-Matt



More information about the R-help mailing list