目录
包加载以及数据的预处理
install.packages("ggtrendline")
library(foreign)
library(ggtrendline)
library(readxl)
library('fpc')
library('ggplot2')
library("dbscan")
setwd("E:/LW_DATE/YEB_CD/zuotu/1shikongshuju")
getwd()
#1L4z1mOBSN,3l4z1mIOSN
ly1=read_excel("YEB_LYTJ.xlsx")
xy1=read_excel("YEB_XYTJ.xlsx")
yw1=read_excel("YEB_YWTJ.xlsx")
library(ggplot2)
#J}>]EEPr
data <- data.frame(x = c(3, 1, 5, 2, 4), y = c("C", "A", "E", "B", "D"))
xly=c(1:61)
xxy=c(1:nrow(xy1[8]))
xyw=c(1:nrow(yw1[8]))
# 数据整理---------------------------
lywypx <- data.frame(scale(ly1[[8]],center = T,scale = T),scale(ly1[[2]],center = T,scale = T))
lyscpx <- data.frame(scale(ly1[[9]],center = T,scale = T),scale(ly1[[4]],center = T,scale = T))
lycspx <- data.frame(scale(ly1[[10]],center = T,scale = T),scale(ly1[[6]],center = T,scale = T))
xywypx <- data.frame(scale(xy1[[8]],center = T,scale = T),scale(xy1[[2]],center = T,scale = T))
xyscpx <- data.frame(scale(xy1[[9]],center = T,scale = T),scale(xy1[[4]],center = T,scale = T))
xycspx <- data.frame(scale(xy1[[10]],center = T,scale = T),scale(xy1[[6]],center = T,scale = T))
ywwypx <- data.frame(scale(yw1[[8]],center = T,scale = T),scale(yw1[[2]],center = T,scale = T))
ywscpx <- data.frame(scale(yw1[[9]],center = T,scale = T),scale(yw1[[4]],center = T,scale = T))
ywcspx <- data.frame(scale(yw1[[10]],center = T,scale = T),scale(yw1[[6]],center = T,scale = T))
#绘图母版主题设置---------
theme_set(theme_bw())#主题设置
col= c("#0984e3","#74b9ff", "#0984e3", "#0984e3","#0984e3","#0984e3","#0984e3","#0984e3","#ff7979")
col= c("#eb4d4b","#74b9ff", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b", "#eb4d4b")
计算KNN以及eps并且绘图
#plywypj-------------
#绘制KNN距离图
# 数据行与K值确定
rowslywypx <- nrow(lywypx[1])
knnlywypx <- round(sqrt(rowslywypx), 0)#k值
dslywypx <- kNNdist(lywypx, k = knnlywypx)#计算knn
dflywypx <- data.frame(DataPoints = 1:length(dslywypx), Distance = dslywypx)
epslywypx=0.6
kjlywypx=ggplot(dflywypx, aes(x = DataPoints, y = Distance)) +
geom_line() +
geom_hline(yintercept = epslywypx, color = "red", linetype = "dashed",size=1)+
geom_text(x = max(dflywypx$DataPoints)*0.15, y = epslywypx + 0.05*max(dflywypx$Distance), size = 5,label =paste0("y = ", epslywypx[1]),color = "red",family = "serif")+
geom_text(x = max(dflywypx$DataPoints)*0.15, y = max(dflywypx$Distance)*0.95, size = 5, # 添加文本标签
label = paste0("k = ", knnlywypx[1]),family = "serif")+
labs(x = NULL, y = NULL)+
scale_y_continuous(expand = c(0, 0))+scale_x_continuous(expand = c(0, 0))
kjlywypx
#确定eps后绘制dbscan的图
mlywypx <- dbscan::dbscan(lywypx,eps=epslywypx[1],minPts=6)
dblywypx=ggplot(lywypx,aes(x=lywypx[[2]], y=lywypx[[1]])) +
geom_point(size=2.5, colour = "black", shape = 21, stroke = 0.5,alpha=0.4,aes(fill=factor(mlywypx$cluster)))+
scale_fill_manual(values = col) +
geom_hline(yintercept=median(lywypx[[1]]), color = "#ff5600", linetype = "solid",size=0.4)+
geom_vline(xintercept=median(lywypx[[2]]), color = "#ff5600", linetype = "solid",size=0.4)+
scale_y_continuous(
limits = c(-2, 6),
breaks = c(seq(-2, 6, length = 5)),
labels = waiver(),
expand = c(0, 0)
) + scale_x_continuous(
limits = c(-2, 6),
breaks = c(seq(-2, 6, length = 5)),
labels = waiver(),
expand = c(0, 0)
) +coord_fixed(ratio = 8 / 8) + theme(panel.grid.major = element_line(colour = "gray75",
linetype = "dashed"), panel.grid.minor = element_line(colour = "gray90",
linetype = "dotted"), axis.text = element_text(family = "serif",
size = 15), axis.text.x = element_text(family = "serif"),
panel.background = element_rect(fill = NA)) +labs(x = NULL, y = NULL)+ theme(legend.position = "none") +labs(colour = NULL)
dblywypx
#plyscpj-------------
#绘制KNN距离图
# 数据行与K值确定
rowslyscpx <- nrow(lyscpx[1])
knnlyscpx <- round(sqrt(rowslyscpx), 0)#k值
dslyscpx <- kNNdist(lyscpx, k = knnlyscpx)#计算knn
dflyscpx <- data.frame(DataPoints = 1:length(dslyscpx), Distance = dslyscpx)
epslyscpx=0.2
kjlyscpx=ggplot(dflyscpx, aes(x = DataPoints, y = Distance)) +
geom_line() +
geom_hline(yintercept = epslyscpx, color = "red", linetype = "dashed",size=1)+
geom_text(x = max(dflyscpx$DataPoints)*0.15, y = epslyscpx + 0.05*max(dflyscpx$Distance), size = 5,label =paste0("y = ", epslyscpx[1]),color = "red",family = "serif")+
geom_text(x = max(dflyscpx$DataPoints)*0.15, y = max(dflyscpx$Distance)*0.95, size = 5, # 添加文本标签
label = paste0("k = ", knnlyscpx[1]),family = "serif")+
labs(x = NULL, y = NULL)+
scale_y_continuous(expand = c(0, 0))+scale_x_continuous(expand = c(0, 0))
kjlyscpx
#确定eps后绘制dbscan的图
mlyscpx <- dbscan::dbscan(lyscpx,eps=epslyscpx[1],minPts=6)
dblyscpx=ggplot(lyscpx,aes(x=lyscpx[[2]], y=lyscpx[[1]])) +
geom_point(size=2.5, colour = "black", shape = 21, stroke = 0.5,alpha=0.4,aes(fill=factor(mlyscpx$cluster)))+ scale_fill_manual(values = col) +
geom_hline(yintercept=median(lyscpx[[1]]), color = "#ff5600", linetype = "solid",size=0.4)+
geom_vline(xintercept=median(lyscpx[[2]]), color = "#ff5600", linetype = "solid",size=0.4)+
scale_y_continuous(
limits = c(-2, 6),
breaks = c(seq(-2, 6, length = 5)),
labels = waiver(),
expand = c(0, 0)
) + scale_x_continuous(
limits = c(-2, 6),
breaks = c(seq(-2, 6, length = 5)),
labels = waiver(),
expand = c(0, 0)
) +coord_fixed(ratio = 8 / 8) + theme(panel.grid.major = element_line(colour = "gray75",
linetype = "dashed"), panel.grid.minor = element_line(colour = "gray90",
linetype = "dotted"), axis.text = element_text(family = "serif",
size = 15), axis.text.x = element_text(family = "serif"),
panel.background = element_rect(fill = NA)) +labs(x = NULL, y = NULL)+ theme(legend.position = "none") +labs(colour = NULL)
dblyscpx
#plycspj-------------
#绘制KNN距离图
# 数据行与K值确定
rowslycspx <- nrow(lycspx[1])
knnlycspx <- round(sqrt(rowslycspx), 0)#k值
dslycspx <- kNNdist(lycspx, k = knnlycspx)#计算knn
dflycspx <- data.frame(DataPoints = 1:length(dslycspx), Distance = dslycspx)
epslycspx=0.6
kjlycspx=ggplot(dflycspx, aes(x = DataPoints, y = Distance)) +
geom_line() +
geom_hline(yintercept = epslycspx, color = "red", linetype = "dashed",size=1)+
geom_text(x = max(dflycspx$DataPoints)*0.15, y = epslycspx + 0.05*max(dflycspx$Distance), size = 5,label =paste0("y = ", epslycspx[1]),color = "red",family = "serif")+
geom_text(x = max(dflycspx$DataPoints)*0.15, y = max(dflycspx$Distance)*0.95, size = 5, # 添加文本标签
label = paste0("k = ", knnlycspx[1]),family = "serif")+
labs(x = NULL, y = NULL)+
scale_y_continuous(expand = c(0, 0))+scale_x_continuous(expand = c(0, 0))
kjlycspx
#确定eps后绘制dbscan的图
mlycspx <- dbscan::dbscan(lycspx,eps=epslycspx[1],minPts=6)
dblycspx=ggplot(lycspx,aes(x=lycspx[[2]], y=lycspx[[1]])) +
geom_point(size=2.5, colour = "black", shape = 21, stroke = 0.5,alpha=0.4,aes(fill=factor(mlycspx$cluster)))+ scale_fill_manual(values = col) +
geom_hline(yintercept=median(lycspx[[1]]), color = "#ff5600", linetype = "solid",size=0.4)+
geom_vline(xintercept=median(lycspx[[2]]), color = "#ff5600", linetype = "solid",size=0.4)+
scale_y_continuous(
limits = c(-4, 4),
breaks = c(seq(-4, 4, length = 5)),
labels = waiver(),
expand = c(0, 0)
) + scale_x_continuous(
limits = c(-4, 4),
breaks = c(seq(-4, 4, length = 5)),
labels = waiver(),
expand = c(0, 0)
) +coord_fixed(ratio = 8 / 8) + theme(panel.grid.major = element_line(colour = "gray75",
linetype = "dashed"), panel.grid.minor = element_line(colour = "gray90",
linetype = "dotted"), axis.text = element_text(family = "serif",
size = 15), axis.text.x = element_text(family = "serif"),
panel.background = element_rect(fill = NA)) +labs(x = NULL, y = NULL)+ theme(legend.position = "none") +labs(colour = NULL)
dblycspx
#pxywypj-------------
#绘制KNN距离图
# 数据行与K值确定
rowsxywypx <- nrow(xywypx[1])
knnxywypx <- round(sqrt(rowsxywypx), 0)#k值
dsxywypx <- kNNdist(xywypx, k = knnxywypx)#计算knn
dfxywypx <- data.frame(DataPoints = 1:length(dsxywypx), Distance = dsxywypx)
epsxywypx=0.2
kjxywypx=ggplot(dfxywypx, aes(x = DataPoints, y = Distance)) +
geom_line() +
geom_hline(yintercept = epsxywypx, color = "red", linetype = "dashed",size=1)+
geom_text(x = max(dfxywypx$DataPoints)*0.15, y = epsxywypx + 0.05*max(dfxywypx$Distance), size = 5,label =paste0("y = ", epsxywypx[1]),color = "red",family = "serif")+
geom_text(x = max(dfxywypx$DataPoints)*0.15, y = max(dfxywypx$Distance)*0.95, size = 5, # 添加文本标签
label = paste0("k = ", knnxywypx[1]),family = "serif")+
labs(x = NULL, y = NULL)+
scale_y_continuous(expand = c(0, 0))+scale_x_continuous(expand = c(0, 0))
kjxywypx
#确定eps后绘制dbscan的图
mxywypx <- dbscan::dbscan(xywypx,eps=epsxywypx[1],minPts=6)
dbxywypx=ggplot(xywypx,aes(x=xywypx[[2]], y=xywypx[[1]])) +
geom_point(size=2.5, colour = "black", shape = 21, stroke = 0.5,alpha=0.4,aes(fill=factor(mxywypx$cluster)))+ scale_fill_manual(values = col) +
geom_hline(yintercept=median(xywypx[[1]]), color = "#ff5600", linetype = "solid",size=0.4)+
geom_vline(xintercept=median(xywypx[[2]]), color = "#ff5600", linetype = "solid",size=0.4)+
scale_y_continuous(
limits = c(-2, 6),
breaks = c(seq(-2, 6, length = 5)),
labels = waiver(),
expand = c(0, 0)
) + scale_x_continuous(
limits = c(-10, 6),
breaks = c(seq(-10, 6, length = 5)),
labels = waiver(),
expand = c(0, 0)
) +coord_fixed(ratio = 16 / 8) + theme(panel.grid.major = element_line(colour = "gray75",
linetype = "dashed"), panel.grid.minor = element_line(colour = "gray90",
linetype = "dotted"), axis.text = element_text(family = "serif",
size = 15), axis.text.x = element_text(family = "serif"),
panel.background = element_rect(fill = NA)) +labs(x = NULL, y = NULL)+ theme(legend.position = "none") +labs(colour = NULL)
dbxywypx
#pxyscpj-------------
#绘制KNN距离图
# 数据行与K值确定
rowsxyscpx <- nrow(xyscpx[1])
knnxyscpx <- round(sqrt(rowsxyscpx), 0)#k值
dsxyscpx <- kNNdist(xyscpx, k = knnxyscpx)#计算knn
dfxyscpx <- data.frame(DataPoints = 1:length(dsxyscpx), Distance = dsxyscpx)
epsxyscpx=0.2
kjxyscpx=ggplot(dfxyscpx, aes(x = DataPoints, y = Distance)) +
geom_line() +
geom_hline(yintercept = epsxyscpx, color = "red", linetype = "dashed",size=1)+
geom_text(x = max(dfxyscpx$DataPoints)*0.15, y = epsxyscpx + 0.05*max(dfxyscpx$Distance), size = 5,label =paste0("y = ", epsxyscpx[1]),color = "red",family = "serif")+
geom_text(x = max(dfxyscpx$DataPoints)*0.15, y = max(dfxyscpx$Distance)*0.95, size = 5, # 添加文本标签
label = paste0("k = ", knnxyscpx[1]),family = "serif")+
labs(x = NULL, y = NULL)+
scale_y_continuous(expand = c(0, 0))+scale_x_continuous(expand = c(0, 0))
kjxyscpx
#确定eps后绘制dbscan的图
mxyscpx <- dbscan::dbscan(xyscpx,eps=epsxyscpx[1],minPts=6)
dbxyscpx=ggplot(xyscpx,aes(x=xyscpx[[2]], y=xyscpx[[1]])) +
geom_point(size=2.5, colour = "black", shape = 21, stroke = 0.5,alpha=0.4,aes(fill=factor(mxyscpx$cluster)))+ scale_fill_manual(values = col) +
geom_hline(yintercept=median(xyscpx[[1]]), color = "#ff5600", linetype = "solid",size=0.4)+
geom_vline(xintercept=median(xyscpx[[2]]), color = "#ff5600", linetype = "solid",size=0.4)+
scale_y_continuous(
limits = c(-2, 6),
breaks = c(seq(-2, 6, length = 5)),
labels = waiver(),
expand = c(0, 0)
) + scale_x_continuous(
limits = c(-10, 10),
breaks = c(seq(-10, 10, length = 5)),
labels = waiver(),
expand = c(0, 0)
) +coord_fixed(ratio = 20 / 8) + theme(panel.grid.major = element_line(colour = "gray75",
linetype = "dashed"), panel.grid.minor = element_line(colour = "gray90",
linetype = "dotted"), axis.text = element_text(family = "serif",
size = 15), axis.text.x = element_text(family = "serif"),
panel.background = element_rect(fill = NA)) +labs(x = NULL, y = NULL)+ theme(legend.position = "none") +labs(colour = NULL)
dbxyscpx
#pxycspj-------------
#绘制KNN距离图
# 数据行与K值确定
rowsxycspx <- nrow(xycspx[1])
knnxycspx <- round(sqrt(rowsxycspx), 0)#k值
dsxycspx <- kNNdist(xycspx, k = knnxycspx)#计算knn
dfxycspx <- data.frame(DataPoints = 1:length(dsxycspx), Distance = dsxycspx)
epsxycspx=0.25
kjxycspx=ggplot(dfxycspx, aes(x = DataPoints, y = Distance)) +
geom_line() +
geom_hline(yintercept = epsxycspx, color = "red", linetype = "dashed",size=1)+
geom_text(x = max(dfxycspx$DataPoints)*0.15, y = epsxycspx + 0.05*max(dfxycspx$Distance), size = 5,label =paste0("y = ", epsxycspx[1]),color = "red",family = "serif")+
geom_text(x = max(dfxycspx$DataPoints)*0.15, y = max(dfxycspx$Distance)*0.95, size = 5, # 添加文本标签
label = paste0("k = ", knnxycspx[1]),family = "serif")+
labs(x = NULL, y = NULL)+
scale_y_continuous(expand = c(0, 0))+scale_x_continuous(expand = c(0, 0))
kjxycspx
#确定eps后绘制dbscan的图
mxycspx <- dbscan::dbscan(xycspx,eps=epsxycspx[1],minPts=6)
dbxycspx=ggplot(xycspx,aes(x=xycspx[[2]], y=xycspx[[1]])) +
geom_point(size=2.5, colour = "black", shape = 21, stroke = 0.5,alpha=0.4,aes(fill=factor(mxycspx$cluster)))+ scale_fill_manual(values = col) +
geom_hline(yintercept=median(xycspx[[1]]), color = "#ff5600", linetype = "solid",size=0.4)+
geom_vline(xintercept=median(xycspx[[2]]), color = "#ff5600", linetype = "solid",size=0.4)+
scale_y_continuous(
limits = c(-4, 4),
breaks = c(seq(-4, 4, length = 5)),
labels = waiver(),
expand = c(0, 0)
) + scale_x_continuous(
limits = c(-4, 4),
breaks = c(seq(-4, 4, length = 5)),
labels = waiver(),
expand = c(0, 0)
) +coord_fixed(ratio = 8 / 8) + theme(panel.grid.major = element_line(colour = "gray75",
linetype = "dashed"), panel.grid.minor = element_line(colour = "gray90",
linetype = "dotted"), axis.text = element_text(family = "serif",
size = 15), axis.text.x = element_text(family = "serif"),
panel.background = element_rect(fill = NA)) +labs(x = NULL, y = NULL)+ theme(legend.position = "none") +labs(colour = NULL)
dbxycspx
#pywwypj-------------
#绘制KNN距离图
# 数据行与K值确定
rowsywwypx <- nrow(ywwypx[1])
knnywwypx <- round(sqrt(rowsywwypx), 0)#k值
dsywwypx <- kNNdist(ywwypx, k = knnywwypx)#计算knn
dfywwypx <- data.frame(DataPoints = 1:length(dsywwypx), Distance = dsywwypx)
epsywwypx=0.2
kjywwypx=ggplot(dfywwypx, aes(x = DataPoints, y = Distance)) +
geom_line() +
geom_hline(yintercept = epsywwypx, color = "red", linetype = "dashed",size=1)+
geom_text(x = max(dfywwypx$DataPoints)*0.15, y = epsywwypx + 0.05*max(dfywwypx$Distance), size = 5,label =paste0("y = ", epsywwypx[1]),color = "red",family = "serif")+
geom_text(x = max(dfywwypx$DataPoints)*0.15, y = max(dfywwypx$Distance)*0.95, size = 5, # 添加文本标签
label = paste0("k = ", knnywwypx[1]),family = "serif")+
labs(x = NULL, y = NULL)+
scale_y_continuous(expand = c(0, 0))+scale_x_continuous(expand = c(0, 0))
kjywwypx
#确定eps后绘制dbscan的图
mywwypx <- dbscan::dbscan(ywwypx,eps=epsywwypx[1],minPts=6)
dbywwypx=ggplot(ywwypx,aes(x=ywwypx[[2]], y=ywwypx[[1]])) +
geom_point(size=2.5, colour = "black", shape = 21, stroke = 0.4,alpha=0.4,aes(fill=factor(mywwypx$cluster)))+ scale_fill_manual(values = col) +
geom_hline(yintercept=median(ywwypx[[1]]), color = "#ff5600", linetype = "solid",size=0.4)+
geom_vline(xintercept=median(ywwypx[[2]]), color = "#ff5600", linetype = "solid",size=0.4)+
scale_y_continuous(
limits = c(-2, 6),
breaks = c(seq(-2, 6, length = 5)),
labels = waiver(),
expand = c(0, 0)
) + scale_x_continuous(
limits = c(-24, 12),
breaks = c(seq(-24, 12, length = 4)),
labels = waiver(),
expand = c(0, 0)
) +coord_fixed(ratio = 36/8) + theme(panel.grid.major = element_line(colour = "gray75",
linetype = "dashed"), panel.grid.minor = element_line(colour = "gray90",
linetype = "dotted"), axis.text = element_text(family = "serif",
size = 15), axis.text.x = element_text(family = "serif"),
panel.background = element_rect(fill = NA)) +labs(x = NULL, y = NULL)+ theme(legend.position = "none") +labs(colour = NULL)
dbywwypx
#pywscpj-------------
#绘制KNN距离图
# 数据行与K值确定
rowsywscpx <- nrow(ywscpx[1])
knnywscpx <- round(sqrt(rowsywscpx), 0)#k值
dsywscpx <- kNNdist(ywscpx, k = knnywscpx)#计算knn
dfywscpx <- data.frame(DataPoints = 1:length(dsywscpx), Distance = dsywscpx)
epsywscpx=0.5
kjywscpx=ggplot(dfywscpx, aes(x = DataPoints, y = Distance)) +
geom_line() +
geom_hline(yintercept = epsywscpx, color = "red", linetype = "dashed",size=1)+
geom_text(x = max(dfywscpx$DataPoints)*0.15, y = epsywscpx + 0.05*max(dfywscpx$Distance), size = 5,label =paste0("y = ", epsywscpx[1]),color = "red",family = "serif")+
geom_text(x = max(dfywscpx$DataPoints)*0.15, y = max(dfywscpx$Distance)*0.95, size = 5, # 添加文本标签
label = paste0("k = ", knnywscpx[1]),family = "serif")+
labs(x = NULL, y = NULL)+
scale_y_continuous(expand = c(0, 0))+
scale_x_continuous(expand = c(0, 0))
kjywscpx
#确定eps后绘制dbscan的图
mywscpx <- dbscan::dbscan(ywscpx,eps=epsywscpx[1],minPts=6)
dbywscpx=ggplot(ywscpx,aes(x=ywscpx[[2]], y=ywscpx[[1]])) +
geom_point(size=2.5, colour = "black", shape = 21, stroke = 0.5,alpha=0.4,aes(fill=factor(mywscpx$cluster)))+ scale_fill_manual(values = col) +
geom_hline(yintercept=median(ywscpx[[1]]), color = "#ff5600", linetype = "solid",size=0.4)+
geom_vline(xintercept=median(ywscpx[[2]]), color = "#ff5600", linetype = "solid",size=0.4)+
scale_y_continuous(
limits = c(-20, 60),
breaks = c(seq(-20, 60, length = 5)),
labels = waiver(),
expand = c(0, 0)
) + scale_x_continuous(
limits = c(-60, 60),
breaks = c(seq(-60, 60, length = 5)),
labels = waiver(),
expand = c(0, 0)
) +coord_fixed(ratio = 120 / 80) + theme(panel.grid.major = element_line(colour = "gray75",
linetype = "dashed"), panel.grid.minor = element_line(colour = "gray90",
linetype = "dotted"), axis.text = element_text(family = "serif",
size = 15), axis.text.x = element_text(family = "serif"),
panel.background = element_rect(fill = NA)) +labs(x = NULL, y = NULL)+ theme(legend.position = "none") +labs(colour = NULL)
dbywscpx
#pywcspj-------------
#绘制KNN距离图
# 数据行与K值确定
rowsywcspx <- nrow(ywcspx[1])
knnywcspx <- round(sqrt(rowsywcspx), 0)#k值
dsywcspx <- kNNdist(ywcspx, k = knnywcspx)#计算knn
dfywcspx <- data.frame(DataPoints = 1:length(dsywcspx), Distance = dsywcspx)
epsywcspx=0.10
kjywcspx=ggplot(dfywcspx, aes(x = DataPoints, y = Distance)) +
geom_line() +
geom_hline(yintercept = epsywcspx, color = "red", linetype = "dashed",size=1)+
geom_text(x = max(dfywcspx$DataPoints)*0.15, y = epsywcspx + 0.05*max(dfywcspx$Distance), size = 5,label =paste0("y = ", epsywcspx[1]),color = "red",family = "serif")+
geom_text(x = max(dfywcspx$DataPoints)*0.15, y = max(dfywcspx$Distance)*0.95, size = 5, # 添加文本标签
label = paste0("k = ", knnywcspx[1]),family = "serif")+
labs(x = NULL, y = NULL)+
scale_y_continuous(expand = c(0, 0))+scale_x_continuous(expand = c(0, 0))
kjywcspx
#确定eps后绘制dbscan的图
mywcspx <- dbscan::dbscan(ywcspx,eps=epsywcspx[1],minPts=6)
dbywcspx=ggplot(ywcspx,aes(x=ywcspx[[2]], y=ywcspx[[1]])) +
geom_point(size=2.5, colour = "black", shape = 21, stroke = 0.5,alpha=0.4,aes(fill=factor(mywcspx$cluster)))+ scale_fill_manual(values = col) +
geom_hline(yintercept=median(ywcspx[[1]]), color = "#ff5600", linetype = "solid",size=0.4)+
geom_vline(xintercept=median(ywcspx[[2]]), color = "#ff5600", linetype = "solid",size=0.4)+
scale_y_continuous(
limits = c(-4, 4),
breaks = c(seq(-4, 4, length = 5)),
labels = waiver(),
expand = c(0, 0)
) + scale_x_continuous(
limits = c(-6, 6),
breaks = c(seq(-6, 6, length = 5)),
labels = waiver(),
expand = c(0, 0)
) +coord_fixed(ratio = 12 / 8) + theme(panel.grid.major = element_line(colour = "gray75",
linetype = "dashed"), panel.grid.minor = element_line(colour = "gray90",
linetype = "dotted"), axis.text = element_text(family = "serif",
size = 15), axis.text.x = element_text(family = "serif"),
panel.background = element_rect(fill = NA)) +labs(x = NULL, y = NULL)+ theme(legend.position = "none") +labs(colour = NULL)
dbywcspx
数据导出并做下一步的处理(建议导出为dbf,不受限制)
#数据导出至dbf------
#dcxypx-------
output_JG<- "E:/LW_DATE/YEB_CD/YEBCD_TJ/特殊点提取/特殊点导出R2" #导出路径设置
output_filename <- file.path(output_JG, "xypxfl2.dbf")#导出路径设置文件名+路径
xywy <- mxywypx$cluster
xysc <- mxyscpx$cluster
xycs <- mxycspx$cluster
xypxfl <- data.frame(xy1, xywy, xysc, xycs)
write.dbf(xypxfl,output_filename )#最终导出数据
#dclypx-------
output_JG<- "E:/LW_DATE/YEB_CD/YEBCD_TJ/特殊点提取/特殊点导出R2" #导出路径设置
output_filename <- file.path(output_JG, "lypxfl2.dbf")#导出路径设置文件名+路径
lywy <- mlywypx$cluster
lysc <- mlyscpx$cluster
lycs <- mlycspx$cluster
lypxfl <- data.frame(ly1, lywy, lysc, lycs)
write.dbf(lypxfl,output_filename )#最终导出数据
#dcywpx-------
output_JG<- "E:/LW_DATE/YEB_CD/YEBCD_TJ/特殊点提取/特殊点导出R2" #导出路径设置
output_filename <- file.path(output_JG, "ywpxfl2.dbf")#导出路径设置文件名+路径
ywwy <- mywwypx$cluster
ywsc <- mywscpx$cluster
ywcs <- mywcspx$cluster
ywpxfl <- data.frame(yw1, ywwy, ywsc, ywcs)
write.dbf(ywpxfl,output_filename )#最终导出数据