R语言
grid.path
位于 grid
包(package)。 说明
这些函数创建并绘制一条或多条路径。路径的终点将自动连接到起点。
用法
pathGrob(x, y,
id=NULL, id.lengths=NULL,
pathId=NULL, pathId.lengths=NULL,
rule="winding",
default.units="npc",
name=NULL, gp=gpar(), vp=NULL)
grid.path(...)
参数
x |
指定 x-locations 的数值向量或单位对象。 |
y |
指定 y-locations 的数值向量或单位对象。 |
id |
用于将 |
id.lengths |
用于将 |
pathId |
用于将 |
pathId.lengths |
用于将 |
rule |
指定填充规则的字符值: |
default.units |
指示 |
name |
字符标识符。 |
gp |
类 |
vp |
网格视口对象(或 NULL)。 |
... |
传递给 |
细节
这两个函数都创建一个路径 grob(说明路径的图形对象),但只有 grid.path
绘制路径(并且仅当 draw
是 TRUE
时)。
路径类似于多边形,只不过前者可以包含孔(由填充规则解释);如果路径边界分别包围该区域奇数或非零次数,则它们将填充该区域。
并非所有图形设备都支持此函数:例如xfig
和pictex
不支持。
值
一个抓取对象。
例子
pathSample <- function(x, y, rule, gp = gpar()) {
if (is.na(rule))
grid.path(x, y, id = rep(1:2, each = 4), gp = gp)
else
grid.path(x, y, id = rep(1:2, each = 4), rule = rule, gp = gp)
if (!is.na(rule))
grid.text(paste("Rule:", rule), y = 0, just = "bottom")
}
pathTriplet <- function(x, y, title) {
pushViewport(viewport(height = 0.9, layout = grid.layout(1, 3),
gp = gpar(cex = .7)))
grid.rect(y = 1, height = unit(1, "char"), just = "top",
gp = gpar(col = NA, fill = "grey"))
grid.text(title, y = 1, just = "top")
pushViewport(viewport(layout.pos.col = 1))
pathSample(x, y, rule = "winding",
gp = gpar(fill = "grey"))
popViewport()
pushViewport(viewport(layout.pos.col = 2))
pathSample(x, y, rule = "evenodd",
gp = gpar(fill = "grey"))
popViewport()
pushViewport(viewport(layout.pos.col = 3))
pathSample(x, y, rule = NA)
popViewport()
popViewport()
}
pathTest <- function() {
grid.newpage()
pushViewport(viewport(layout = grid.layout(5, 1)))
pushViewport(viewport(layout.pos.row = 1))
pathTriplet(c(.1, .1, .9, .9, .2, .2, .8, .8),
c(.1, .9, .9, .1, .2, .8, .8, .2),
"Nested rectangles, both clockwise")
popViewport()
pushViewport(viewport(layout.pos.row = 2))
pathTriplet(c(.1, .1, .9, .9, .2, .8, .8, .2),
c(.1, .9, .9, .1, .2, .2, .8, .8),
"Nested rectangles, outer clockwise, inner anti-clockwise")
popViewport()
pushViewport(viewport(layout.pos.row = 3))
pathTriplet(c(.1, .1, .4, .4, .6, .9, .9, .6),
c(.1, .4, .4, .1, .6, .6, .9, .9),
"Disjoint rectangles")
popViewport()
pushViewport(viewport(layout.pos.row = 4))
pathTriplet(c(.1, .1, .6, .6, .4, .4, .9, .9),
c(.1, .6, .6, .1, .4, .9, .9, .4),
"Overlapping rectangles, both clockwise")
popViewport()
pushViewport(viewport(layout.pos.row = 5))
pathTriplet(c(.1, .1, .6, .6, .4, .9, .9, .4),
c(.1, .6, .6, .1, .4, .4, .9, .9),
"Overlapping rectangles, one clockwise, other anti-clockwise")
popViewport()
popViewport()
}
pathTest()
# Drawing multiple paths at once
holed_rect <- cbind(c(.15, .15, -.15, -.15, .1, .1, -.1, -.1),
c(.15, -.15, -.15, .15, .1, -.1, -.1, .1))
holed_rects <- rbind(
holed_rect + matrix(c(.7, .2), nrow = 8, ncol = 2, byrow = TRUE),
holed_rect + matrix(c(.7, .8), nrow = 8, ncol = 2, byrow = TRUE),
holed_rect + matrix(c(.2, .5), nrow = 8, ncol = 2, byrow = TRUE)
)
grid.newpage()
grid.path(x = holed_rects[, 1], y = holed_rects[, 2],
id = rep(1:6, each = 4), pathId = rep(1:3, each = 8),
gp = gpar(fill = c('red', 'blue', 'green')),
rule = 'evenodd')
# Not specifying pathId will treat all points as part of the same path, thus
# having same fill
grid.newpage()
grid.path(x = holed_rects[, 1], y = holed_rects[, 2],
id = rep(1:6, each = 4),
gp = gpar(fill = c('red', 'blue', 'green')),
rule = 'evenodd')
作者
Paul Murrell
也可以看看
相关用法
- R grid.pack 将对象打包在框架内
- R grid.points 绘制数据符号
- R grid.pretty 生成一组合理(“漂亮”)的断点
- R grid.polygon 绘制多边形
- R grid.place 将对象放置在框架内
- R grid.curve 在位置之间绘制曲线
- R grid.draw 画一个网格
- R grid.stroke 描边或填充路径
- R grid.raster 渲染光栅对象
- R grid.force 强制将一个对象放入其组件中
- R grid.display.list 控制网格显示列表
- R grid.show.viewport 绘制网格视口图
- R grid.segments 绘制线段
- R grid.frame 创建用于包装对象的框架
- R grid.group 画一个组
- R grid.text 绘制文字
- R grid.xspline 绘制 X 样条线
- R grid.copy 制作网格图形对象的副本
- R grid.record 封装计算和绘图
- R grid.grab 抓取当前电网输出
- R grid.show.layout 绘制网格布局图
- R grid.convert 不同网格坐标系之间的转换
- R grid.DLapply 修改网格显示列表
- R grid.delay 封装计算并生成grob
注:本文由纯净天空筛选整理自R-devel大神的英文原创作品 Draw a Path。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。