zl程序教程

您现在的位置是:首页 >  Java

当前栏目

[R包推荐] polyclid优雅的绘制多边形

2023-02-18 16:35:32 时间

❝本节来介绍一款R包「polyclid」用来绘制多边形,原文文档链接见下方,代码过程很是简洁各位观众老爷可以去参考官方文档了解具体细节。当然难点也许在于R包的安装,安装编译过程较长各位耐心等待。

原文文档

❝https://polyclid.r-euclid.com/index.html❞

安装R包

devtools::install_github("thomasp85/polyclid")
library(polyclid)
library(tidyverse)

构建坐标系

p <- polygon(
  x = c(0, 2, 2, -1, -0.25, 1, 1, 1.5, 1.2, -1, -3),
  y = c(0, 0, 1.5, 1.5, 1, 0.5, 1.25, 0.75, 0.75, 0.5, -1),
  id = c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2),
  hole_id = c(1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1))

案例一

plot(p, col = c("steelblue", "forestgreen"))

案例二

hole(p[2]) <- circle(point(-0.8, 0.2), 0.05)
plot(p, col = c("steelblue", "forestgreen"))

案例三

p_symdif <- symmetric_difference(p)
plot(p_symdif, col = "steelblue")

案例四

circles <- circle(point(c(1, -2), c(0, 0)), 0.5)
p_union <- union(p, circles)
plot(p_union, col = c("steelblue", "forestgreen"))