简体   繁体   English

UMAP 中的凸面船体 plot - R

[英]Convex hull in UMAP plot - R

I performed a UMAP on the wine dataset and added a convex hull using the ggpubr stat_chull option.我在 wine 数据集上执行了 UMAP,并使用 ggpubr stat_chull 选项添加了一个凸包。 It seems that the convex hull is not closed, how can I fix it?凸包好像没有闭合,怎么解决? any other package I can use?我可以使用任何其他 package 吗?

library(ggplot2)
library(ggpubr)
library(Rtsne)
library(umap)

UCI <- "ftp://ftp.ics.uci.edu/pub"
REPOS <- "machine-learning-databases"
w.url <- sprintf("%s/%s/wine/wine.data", UCI, REPOS)
w <- read.csv(w.url, header=F) 
colnames(w) <- c('Type', 'Alcohol', 'Malic', 'Ash', 
                    'Alcalinity', 'Magnesium', 'Phenols', 
                    'Flavanoids', 'Nonflavanoids',
                    'Proanthocyanins', 'Color', 'Hue', 
                    'Dilution', 'Proline')
w$Type <- as.factor(w$Type)


####For UMAP 
w.umap = umap(w[,2:14])
w.labels = w$Type

head(w.umap$layout, 3)

df <- data.frame(x = w.umap$layout[,1],
                 y = w.umap$layout[,2],
                 wType = w.labels)
ggplot(df, aes(x, y, colour = wType)) + geom_point(size=3) + ggtitle("UMAP") + stat_chull(aes(color = w.labels))

The default geom for stat_chull is a line rather than a polygon. stat_chull的默认几何图形是一条线而不是多边形。 If you change to a polygon, it will automatically join the ends:如果您更改为多边形,它将自动连接末端:

ggplot(df, aes(x, y, colour = wType)) + geom_point(size=3) + 
  ggtitle("UMAP") + 
  stat_chull(aes(color = w.labels, fill = wType), geom = "polygon", alpha = 0.1)

在此处输入图像描述

Here I have filled the polygons faintly for emphasis, but if you don't want this you can set alpha to 0:在这里,为了强调,我已经模糊地填充了多边形,但如果你不想要这个,你可以将 alpha 设置为 0:

ggplot(df, aes(x, y, colour = wType)) + geom_point(size=3) + 
  ggtitle("UMAP") + 
  stat_chull(aes(color = w.labels, fill = wType), geom = "polygon", alpha = 0, size = 2)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM