Skip to content
Prev 184460 / 398500 Next

grid.polygon() + color gradient

[I neglected to check some details in the previous post]

This one should work better,

library(grid)

x= c(0, 0.5, 1)
y= c(0.5, 1, 0.5)
grid.polygon(x=x, y=y, gp=gpar(fill=NA, col="grey90")) # outer shell

xx <- seq(range(x)[1],range(x)[2], length=100)
dx <- diff(xx) # width of clipped triangles
cols <- colorRampPalette(c("green", "lightgray"))(length(dx))

for(ii in seq_along(xx[-length(xx)])){
grid.clip(x=xx[ii], y=0.5,
width= 1.2*dx[ii], # fudge factor to overlap well
height=1,
just="bottom")
# if(ii%%2)# testing with every other masked
grid.polygon(x=c(0, 0.5, 1), y=c(0.5, 1, 0.5), gp=gpar(fill=cols[ii], 
col=cols[ii]))
}





HTH,

baptiste
Kexin Ji wrote: