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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。