{R grid}:如何创建一个半填充颜色的多边形?
(这个问题可能太难了,也许不值得这么麻烦去解决 - 但是,如果有一个简单的解决方案 - 我很想知道)
假设我创建了一个图像(使用 grid 包),如下所示:
require(grid)
grid.newpage()
grid.polygon(x=c((0:4)/10, rep(.5, 5), (10:6)/10, rep(.5, 5)),
y=c(rep(.5, 5), (10:6/10), rep(.5, 5), (0:4)/10),
id=rep(1:5, 4),
gp=gpar(fill=1:5))
但现在,如果我希望某些多边形仅部分填充(假设一个多边形填充 1/3,另一个填充 1/2,另一个完全填充颜色),那么它看起来就像是部分填充的一杯水,该怎么办? 。
我想这可以在构造多边形时完成,问题是,假设我想要仅根据我给出的比例来计算新的多边形 - 如何才能做到这一点。
我的问题的动机来自于想要在徽标图上呈现另一层信息(请参阅 seqLogo 包中的函数 seqLogo)
谢谢。
(This question might be too difficult, and maybe not worth the hassle to solve - however, if there is an easy solution - I would be curious to know)
Let's say I create an image (using the grid package) which looks like this:
require(grid)
grid.newpage()
grid.polygon(x=c((0:4)/10, rep(.5, 5), (10:6)/10, rep(.5, 5)),
y=c(rep(.5, 5), (10:6/10), rep(.5, 5), (0:4)/10),
id=rep(1:5, 4),
gp=gpar(fill=1:5))
But now, what if I wish to have some of the polygons only partially filled (let's say one will be 1/3 filled and another 1/2 filled and the other fully filled with color) So it would look like partially filled glass of water.
I imagine it can be done when constructing the polygons, the question is, assuming I want something to calculate the new polygons only based on the proportions I give it - how can that be done.
The motivation for my question comes from wanting to present another layer of information on logo plots (see the function seqLogo in the package seqLogo)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过绘制两次来部分填充多边形:首先绘制带有轮廓但不填充的整个多边形,然后绘制填充。通过一个简单的矩形示例,您可以更轻松地看到这一点。
You can partially fill a polygon by drawing it twice: first draw the whole thing with an outline but no fill, then draw the filling. You can see this more easily with a simple rectangle example.