欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

R语言绘制Vonoroi图

程序员文章站 2022-10-29 09:57:38
deldir包绘制voronoi图#install.packages("deldir")library(deldir)# dataset.seed(1)x <- runif(60)y <-...

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"))  #填充颜色

R语言绘制Vonoroi图

#改变图形的形状
#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)

R语言绘制Vonoroi图
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()

R语言绘制Vonoroi图

#添加热图
ggplot(df, aes(x, y, fill = dist)) +
  geom_voronoi() +
  geom_point() +
  scale_fill_gradient(low = "#20b2aa",
                      high = "#9370db") #颜色

R语言绘制Vonoroi图

#添加边界线
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图的详细内容,更多关于r语言绘制vonoroi图的资料请关注其它相关文章!