How to apply cross-hatching to a polygon using a grid graphic system?

Several functions in the R base graphics system, including rect() and polygon() , support cross-hatching through their angle= and density= arguments:

 x = c(0, 0.5, 1, 0.5) y = c(0.5, 1, 0.5, 0) par(mar=c(0,0,0,0)) plot.new() polygon(x, y, angle=45, density=10) 

enter image description here

How can I apply a similar cross-hatching to the polygon drawn by grid.polygon() :

 library(grid) grid.newpage() grid.polygon(x,y) 

enter image description here

I looked at the documentation for ?grid.polygon and ?gpar , and looked at Paul Murrell’s book on the R chart, and so far has come to nothing. Am I missing something? If not, is there a simple hack that will make this possible?

+15
r graphics r-grid
Sep 29 '14 at 22:51
source share
1 answer

Here's an example with gridSVG adapted from a presentation by Paul Murrell

 library(gridSVG) library(grid) x = c(0, 0.5, 1, 0.5) y = c(0.5, 1, 0.5, 0) grid.newpage() grid.polygon(x,y, name="goodshape") pat <- pattern(linesGrob(gp=gpar(col="black",lwd=3)), width = unit(5, "mm"), height = unit(5, "mm"), dev.width = 1, dev.height = 1) # Registering pattern registerPatternFill("pat", pat) # Applying pattern fill grid.patternFill("goodshape", label = "pat") grid.export("test-pattern.svg") 

enter image description here

more complex rot is allowed, as svg takes care of clipping.

enter image description here

+21
Sep 29 '14 at 23:19
source share



All Articles