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

前端 未结 1 955
谎友^
谎友^ 2020-12-06 05:03

Several functions in R\'s base graphical system, including rect() and polygon(), support cross-hatching via their angle= and den

相关标签:
1条回答
  • 2020-12-06 05:36

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

    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 grobs are allowed as well, since svg takes care of the clipping.

    enter image description here

    0 讨论(0)
提交回复
热议问题