Reputation: 2051
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)
Upvotes: 4
Views: 1325
Reputation: 121608
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.
Upvotes: 1
Reputation: 10215
Not an answer, just some details
require(grid)
dothegrid <- function(){
grid.newpage()
grid.lines(x=c(0.5, 0.5), y=c(0.25, 0.75), gp=gpar(col=rgb(1, 0, 0, 0.2)))
grid.lines(x=c(0.4, 0.4), y=c(0.25, 0.75), gp=gpar(col=rgb(1, 0, 0, 0.6)))
}
# Window 7
# Make sure to restart RStudio/R before running this
dothegrid() # Rstudio: ok, nothing in RGui
# run again
dothegrid() # makes the lines disappear
pdf("a.pdf")
dothegrid()
dothegrid() # lines stay
dev.off()
png("a.png")
dothegrid() #lines stay
dev.off()
R version 2.15.2 (2012-10-26) Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252
attached base packages: [1] grid stats graphics grDevices utils datasets methods base
Upvotes: 0