如何使用网格图形系统对多边形应用剖面线? [英] How to apply cross-hatching to a polygon using the grid graphical system?

查看:30
本文介绍了如何使用网格图形系统对多边形应用剖面线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R 基础图形系统中的几个函数,包括 rect()polygon(),通过它们的 angle=密度= 参数:

Several functions in R's base graphical system, including rect() and polygon(), support cross-hatching via 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)

如何对由 grid 图形系统的 grid.polygon() 函数绘制的多边形应用类似的交叉影线:

How might I apply similar cross-hatching to a polygon drawn by the grid graphical system's grid.polygon() function:

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

我查看了 ?grid.polygon?gpar 的文档,并浏览了 Paul Murrel 关于 R 图形的书,到目前为止空的.我错过了一些明显的东西吗?如果没有,是否有一些简单的技巧可以使这成为可能?

I've looked in the documentation for ?grid.polygon and ?gpar, and have skimmed through Paul Murrel's book on R graphics, and have so far come up empty. Am I missing something obvious? If not, is there some simple hack which will make this possible?

推荐答案

这是一个使用 gridSVG 改编自 Paul Murrell 的演讲

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")

也允许更复杂的 grobs,因为 svg 负责剪辑.

more complex grobs are allowed as well, since svg takes care of the clipping.

这篇关于如何使用网格图形系统对多边形应用剖面线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆