R语言绘制Vonoroi图的完整代码
短信预约 -IT技能 免费直播动态提醒
deldir包绘制Voronoi图
#install.packages("deldir")
library(deldir)
# data
set.seed(1)
x <- runif(60)
y <- runif(60)
# Calculate Voronoi Tesselation and tiles
tesselation <- deldir(x, y)
tiles <- tile.list(tesselation)
plot(tiles, pch = 19,
border = "black", #边界颜色
showpoints = TRUE, #是否显示点
fillcol = hcl.colors(60, "Sunset")) #填充颜色
#改变图形的形状
#install.packages("polyclip")
library(polyclip)
# Circle环状
s <- seq(0, 2 * pi, length.out = 3000)
circle <- list(x = 0.5 * (1 + cos(s)),
y = 0.5 * (1 + sin(s)))
plot(tiles, pch = 19,
col.pts = "white",
border = "black",
fillcol = hcl.colors(60, "Sunset""),
clipp = circle)
ggplot2绘制Voronoi图
library(ggvoronoi)
library(ggplot2)
set.seed(1)
x <- sample(1:600, size = 100)
y <- sample(1:600, size = 100)
dist <- sqrt((x - 200) ^ 2 + (y - 200) ^ 2)
df <- data.frame(x, y, dist = dist)
ggplot(df, aes(x, y)) +
stat_voronoi(geom = "path",
color = 6,
lwd = 0.7,
linetype = 1)
geom_point()
#添加热图
ggplot(df, aes(x, y, fill = dist)) +
geom_voronoi() +
geom_point() +
scale_fill_gradient(low = "#20B2AA",
high = "#9370DB") #颜色
#添加边界线
ggplot(df, aes(x, y, fill = dist)) +
geom_voronoi() +
stat_voronoi(geom = "path") +
geom_point()+
scale_fill_gradient(low = "#20B2AA",
high = "#9370DB")
#theme(legend.position = "none") # 去掉右侧图例标签
以上就是R语言绘制Vonoroi图的详细内容,更多关于R语言绘制Vonoroi图的资料请关注编程网其它相关文章!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341