I want to create transparent lines with the grid package.
This works (only for horizontal and vertical lines):
require(grid)
grid.newpage()
grid.rect(x=0.5, y=0.5, width=0, height=0.5, gp=gpar(col=rgb(1, 0, 0, .4)))
However, this doesn't:
grid.newpage()
grid.lines(x=c(0.5, 0.5), y=c(0.25, 0.75), gp=gpar(col=rgb(1, 0, 0, .4)))
I tried this both in RStudio v0.97.237 and in RGui 2.15.2.
UPDATE: when I put this second code chunk in a function, such as in the dothegrid() in the first answer below, it does work in RStudio, but only after a restart, of after clicking "Clear All" in RStudio's plot device pane.
UPDATE2: now we're getting somewhere: It only works when clicking on "Clear All" in RStudio, followed by the grid.lines statement (WITHOUT the grid.newpage() statement)
I don't think the proble is due to newpage command.
I play with units :
this doesn't work
grid.newpage()
grid.lines(x,y, gp=gpar(col='red'),default.units = "npc")
But when I change the default units this work :
grid.newpage()
grid.lines(x,y, gp=gpar(col='red',alpha=0.4),default.units='naif')
Notice that that naif is used when you pass the functions a numeric vector without any associated units.