{R grid}:如何创建一个半填充颜色的多边形?

发布于 2024-09-08 08:48:36 字数 559 浏览 1 评论 0原文

(这个问题可能太难了,也许不值得这么麻烦去解决 - 但是,如果有一个简单的解决方案 - 我很想知道)

假设我创建了一个图像(使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千笙结 2024-09-15 08:48:36

您可以通过绘制两次来部分填充多边形:首先绘制带有轮廓但不填充的整个多边形,然后绘制填充。通过一个简单的矩形示例,您可以更轻松地看到这一点。

x <- c(left = 0.25, right = 0.75)
y <- c(bottom = 0.1, mid = 0.6, top = 0.9)

grid.newpage()
grid.polygon(x =  rep(x[c("left", "right", "right", "left")], 2),
             y =  y[rep(c("bottom", "top", "bottom", "mid"), each = 2)],
             id = rep(1:2, each = 4),
             gp = gpar(fill = c(NA, "blue")))

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.

x <- c(left = 0.25, right = 0.75)
y <- c(bottom = 0.1, mid = 0.6, top = 0.9)

grid.newpage()
grid.polygon(x =  rep(x[c("left", "right", "right", "left")], 2),
             y =  y[rep(c("bottom", "top", "bottom", "mid"), each = 2)],
             id = rep(1:2, each = 4),
             gp = gpar(fill = c(NA, "blue")))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文