Skip to content
Prev 35304 / 63421 Next

raster support in graphics devices

Hi,

[my message below is a bit off-topic]

2009/12/14 Paul Murrell <p.murrell at auckland.ac.nz>:
That would be nice.

I first thought that this new rasterGrob would be a good way to
implement some kind of filling pattern for grid graphics, but after
some more testing I was surprised to see that a similar approach with
vector patterns could result in more efficient, better output. Of
course raster filling patterns could still be nice to have for fancy
images or gradients.

One thing that worries me with the approach I've taken below is that
the grob is not vectorized. In particular, if one was to use it as a
building block for histograms (as in base graphics' density parameter)
each rectangle would have to be drawn in sequence. I can of course
Vectorize() this grob into a new one (gTree) but I haven't seen any
examples like this before. Does this sound reasonable? (argument
explosion might be another problem...)

Best regards,

baptiste

Below is the gist of my experiments (the first part is not related to
grid.raster and runs in current R).


library(grid)

## vector patterns
source("http://gridextra.googlecode.com/svn/trunk/R/vpattern.r")

dev.new()
grid.newpage()
grid.vpattern(x=0.2, width=unit(3,"cm"), height=unit(0.5,"npc"),
             motif="points", motif.params=list(pch=22,
                               gp=gpar(cex=0.8, lwd=5, col="grey90",
fill="grey95")), clip=T)

grid.vpattern(x=0.5, width=unit(0.3,"npc"), height=unit(0.5,"npc"),
             motif="segments", motif.params=list(angle=45,
                                 gp=gpar(lty=2, col="grey", lwd=2.4)))

grid.vpattern(x=0.5, y=0.9, width=unit(0.5,"npc"), height=unit(1,"cm"),
             motif="points", motif.params=list(pch="+"), clip=F,
pattern.offset=c(1, 0.5))

grid.vpattern(x=0.8,  width=unit(0.2,"npc"), height=unit(0.2,"npc"),
             motif="grid", motif.params=list(angle=45,
                             gp=gpar(lwd=10, col="grey90")), clip=T,
pattern.offset=c(-1, 0.5))

grid.vpattern(x=0.5, y=0.1, width=unit(0.9,"npc"), height=unit(0.1,"npc"),
             motif="grid", motif.params=list(angle=30, gp=gpar(col="red")),
              gp=gpar(alpha=0.1, fill="red"))

## raster patterns

source("http://gridextra.googlecode.com/svn/trunk/R/rpattern.r")

## a raster motif
plus <- function(..., width=5, height=5){
  x11(width=width/25.4, height=height/25.4)
  grid.points(x=unit(0.5, "npc"), y=unit(0.5, "npc"),
              pch=3, size=unit(2, "mm"), gp=gpar(), ...)
  m <- grid.cap()
  dev.off()
  invisible(m)
}
.plus <- plus()

g1 <- rpatternGrob(x=0.5, y=0.4, width=unit(3.7, "cm"),
                   height=unit(0.4, "npc"),
                   clip=TRUE, motif=.plus)

dev.new()
grid.draw(g1)

Thread (27 messages)

Paul Murrell raster support in graphics devices Nov 30 Baptiste Auguie raster support in graphics devices Dec 1 Paul Murrell raster support in graphics devices Dec 1 Baptiste Auguie raster support in graphics devices Dec 3 Gabor Grothendieck raster support in graphics devices Dec 4 Baptiste Auguie raster support in graphics devices Dec 4 Gabor Grothendieck raster support in graphics devices Dec 4 Gabor Grothendieck raster support in graphics devices Dec 4 Hadley Wickham raster support in graphics devices Dec 4 Gabor Grothendieck raster support in graphics devices Dec 4 Romain Francois raster support in graphics devices Dec 4 Gabor Grothendieck raster support in graphics devices Dec 4 Hadley Wickham raster support in graphics devices Dec 4 Tobias Verbeke raster support in graphics devices Dec 5 Baptiste Auguie raster support in graphics devices Dec 5 Romain Francois raster support in graphics devices Dec 5 Simon Urbanek raster support in graphics devices Dec 5 Romain Francois raster support in graphics devices Dec 6 Romain Francois raster support in graphics devices Dec 6 Simon Urbanek raster support in graphics devices Dec 6 Romain Francois raster support in graphics devices Dec 6 Paul Murrell raster support in graphics devices Dec 6 Paul Murrell raster support in graphics devices Dec 6 Baptiste Auguie raster support in graphics devices Dec 6 Baptiste Auguie raster support in graphics devices Dec 6 Paul Murrell raster support in graphics devices Dec 13 Baptiste Auguie raster support in graphics devices Dec 14