tags:

views:

88

answers:

1

I'd like to export plotting symbols form R as a png graphic. But I haven't found a perfect way yet.

Using

png("symbol.png",width=20, height=20, bg="transparent")
par(mar=c(0,0,0,0))
plot.new()
symbols(1, 1, circles=0.3, bg=2, inches=FALSE, lwd=2, bty="n")
dev.off()

creates a little border around the symbol (I'd like it to be transparent) and the symbol isn't filling the whole space.

symbol

Is there a more specific way of doing this ?

+1  A: 

In addition to the margins, you need to eliminate axes and the space for them, and turn off the auto-extending of the axis limits:

par(xaxs="i", yaxs="i")  # 'internal' axis style - no extending
par(xaxt="n", yaxt="n")  # remove axes
par(mgp=c(0,0,0))        # remove room for title and axis labels
par(mar=c(0,0,0,0))      # remove margins
symbols(0,0, circles=1, bg=2, fg=NA, inches=FALSE, bty="n", 
        xlim=c(-1,1), ylim=c(-1,1)) #ensure limits match the size of the circle

The fg=NA part removes the foreground of the symbol which is the border of the circle. Hopefully this looks more like what you had in mind.

Aniko
It's getting better (more centred), but there is still that black border as an 'L'. I've added an image to illustrate.
Etiennebr
@Etiennebr Those are the axes. I edited the response to remove them as well.
Aniko
Indeed, it's working. The border disappeared. The only downside now, is that I cannot get it centred. It is closer from upper and left side ! Do you have an idea ?If you use png("symbol.png", width=20, height=20, bg="transparent")...your code...dev.off(), you'll see.
Etiennebr