如何使用网格图形系统将交叉阴影应用于多边形? [英] How to apply cross-hatching to a polygon using the grid graphical system?

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

问题描述

基本图形系统中的几个函数,包括 rect() polygon(),支持交叉影线通过它们的 angle = density = 参数:



<$ p (0,0,0,1,0.5)
y = c(0.5,1,0.5,0)
par(mar = c(0,0, 0,0))
plot.new()
多边形(x,y,angle = 45,density = 10)



如何将类似交叉阴影应用于由网格图形系统的 grid.polygon()函数绘制的多边形:

 库(网格)
grid.newpage()
grid.polygon(x,y)



我查看了?grid.polygon ?gpar ,并通过Paul Murrel的书进行了探索R图形,并且迄今为止都是空着的。我错过了明显的东西吗?如果不是,是否有一些简单的黑客可以使这成为可能?

解决方案

下面是一个使用gridSVG的例子 Paul Murrell的介绍



<$ (gridSVG)
library(grid)
x = c(0,0.5,1,0.5)
y = c(0.5,1,0.5,0,0,0,0,0,0,0) 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)

#注册模式
registerPatternFill(pat,pat)
#应用模式填充
grid.patternFill(goodshape,label =pat )

grid.export(test-pattern.svg)



更复杂的grobs也可以,因为svg tak




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)

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)

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?

解决方案

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

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

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

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