R語言繪制Vonoroi圖的完整代碼
更新時(shí)間:2021年06月20日 15:52:54 作者:作圖幫
今天來給大家分享一篇教程關(guān)于R語言繪制Vonoroi圖的完整代碼,包括deldir包繪制Voronoi圖,ggplot2繪制Voronoi圖的實(shí)現(xiàn)代碼,感興趣的朋友跟隨小編一起看看吧
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, #是否顯示點(diǎn)
fillcol = hcl.colors(60, "Sunset")) #填充顏色

#改變圖形的形狀
#install.packages("polyclip")
library(polyclip)
# Circle環(huán)狀
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") # 去掉右側(cè)圖例標(biāo)簽

以上就是R語言繪制Vonoroi圖的詳細(xì)內(nèi)容,更多關(guān)于R語言繪制Vonoroi圖的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
R語言因子型數(shù)值轉(zhuǎn)數(shù)值型的操作
這篇文章主要介紹了R語言因子型數(shù)值轉(zhuǎn)數(shù)值型的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-04-04
R語言學(xué)習(xí)數(shù)據(jù)獲取操作示例詳解
這篇文章主要為大家介紹了R語言學(xué)習(xí)數(shù)據(jù)獲取操作示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
使用R語言繪制散點(diǎn)圖結(jié)合邊際分布圖教程
這篇文章主要介紹了使用R語言利用ggplot繪制散點(diǎn)圖,并且在圖像的兩邊繪制邊際分布圖(包括邊際直方圖與邊際密度函數(shù))我們這里介紹兩種方法進(jìn)行繪制2021-11-11
R語言中向量和矩陣簡單運(yùn)算的實(shí)現(xiàn)
這篇文章主要介紹了R語言中向量和矩陣簡單運(yùn)算的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03
R語言ggplot2實(shí)現(xiàn)將多個(gè)照片拼接到一起
本文主要介紹了R語言ggplot2實(shí)現(xiàn)將多個(gè)照片拼接到一起,文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-07-07
R語言-如何將循環(huán)所得的矩陣組成一個(gè)矩陣
這篇文章主要介紹了R語言實(shí)現(xiàn)將循環(huán)所得的矩陣組成一個(gè)矩陣的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-04-04

