❝本节来介绍一款R包「polyclid」用来绘制多边形,原文文档链接见下方,代码过程很是简洁各位观众老爷可以去参考官方文档了解具体细节。当然难点也许在于R包的安装,安装编译过程较长各位耐心等待。
❝https://polyclid.r-euclid.com/index.html❞
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"))