R PCA生成的图形可疑,无法确定原因
我的PCA有问题。PC1结果是二进制的,我不明白为什么,因为我的变量都不是二进制的 df=蜜蜂R PCA生成的图形可疑,无法确定原因,r,ggplot2,pca,R,Ggplot2,Pca,我的PCA有问题。PC1结果是二进制的,我不明白为什么,因为我的变量都不是二进制的 df=蜜蜂 pca_dat_condition <- bees %>% ungroup() %>% select(Length.1:Length.25, OBJECTID, Local, Elevation, Longitude, Latitude, Cubital.Index) %>% na.omit() pca_dat_first <- pca_dat_co
pca_dat_condition <- bees %>% ungroup() %>%
select(Length.1:Length.25, OBJECTID, Local, Elevation, Longitude,
Latitude, Cubital.Index) %>%
na.omit()
pca_dat_first <- pca_dat_condition %>% #remove the final nonnumerical information
select(-Local, -OBJECTID, -Elevation, -Longitude, -Latitude)
pca <- pca_dat_first%>%
scale() %>%
prcomp()
# add identifying information back into PCA data
pca_data <- data.frame(pca$x, Local=pca_dat_condition$Local, ID =
pca_dat_condition$OBJECTID, elevation = pca_dat_condition$Elevation,
Longitude = pca_dat_condition$Longitude, Latitude =
pca_dat_condition$Latitude)
ggplot(pca_data, aes(x=PC1, y=PC2, color = Latitude)) +
geom_point() +ggtitle("PC1 vs PC2: All Individuals") +
scale_colour_gradient(low = "blue", high = "red")
我没有收到代码中的任何错误消息,当我查看数据帧时,没有任何东西看起来不合适。我应该为PCA使用不同的函数吗?了解我的图表为什么会是这样吗
之前,我做了相同的主成分分析,但对每个局部区域的平均值,而这是每个个体的平均值,结果是一个正常的主成分分析,没有明确的聚类。我不明白为什么在看单个点时会出现这个问题。我可能以一种不稳定的方式合并了一些其他数据帧,但数据集的结构似乎完全正常
在删除异常值之前
之后
你做过初步的探索性分析吗?长度数据的分布似乎很奇怪。试试histbees[,1]。我猜可能是某种解析或转换错误。或者可能是单位的混合?厘米和微米?另一种奇怪的关系。尝试HIGH1=其中PCA_数据$PC1>5;ggplotpca_数据[-HIGH1,],aesx=PC1,y=PC2,颜色=纬度+几何点+ggtitlePC1 vs PC2:所有个体+比例颜色梯度低=蓝色,高=红色长度中的异常值a似乎仅限于三个个体。将这些从数据集中删除似乎会使事情看起来更好。仔细检查单位,它们都是相同的。我正在研究长度和历史,但没有从中得到任何有见地的东西。谢谢!对于ggplot:bees.pca
bees <- read.csv(paste0("https://gist.githubusercontent.com/AkselA/",
"08a4e78a6a29a918ed597e9a32adc228/raw/",
"6d0005fad4cb91830bcf7087176283b18683e9cd/bees.csv"),
header=TRUE)
# bees <- bees[bees[,1] < 10,] # This will remove the three offending rows
bees <- na.omit(bees)
bees.cond <- bees[, grep("Length|OBJ|Loc|Ele|Lon|Lat|Cubi", colnames(bees))]
bees.first <- bees[, grep("Length|Cubi", colnames(bees))]
summary(bees.first)
par(mfrow=c(7, 4), mar=rep(1, 4))
q <- lapply(1:ncol(bees.first), function(x) {
h <- hist(scale(bees.first[, x]), plot=FALSE)
h$counts <- log1p(h$counts)
plot(h, main="", axes=FALSE, ann=FALSE)
legend("topright", legend=names(bees.first[x]),
bty="n", cex=0.8, adj=c(0, -2), xpd=NA)
})
bees.pca <- prcomp(bees.first, scale.=TRUE)
biplot(bees.pca)