我已经使用 K-means 聚类对一些值进行了聚类。我绘制了三张图,我想要第三张图的图例。我使用该lengend()
函数绘制了一个图例,但图例中没有出现图例(见图)并且没有报告错误。
library(cluster)
library(MASS)
par(mfrow=c(1,3))
par(oma=c(5,0,3,0))
dat <- read.table("representative_for_r.txt", header=TRUE)
data.p <- as.matrix(dat$Average_RMSD)
# Determine number of clusters
wss <- (nrow(data.p)-1)*sum(apply(data.p,2,var))
for (i in 2:15) wss[i] <- sum(kmeans(data.p,centers=i)$withinss)
plot(1:15, wss, type="b", xlab="Number of Clusters",ylab="Within groups sum of squares")
# K-Means Cluster Analysis
fit <- kmeans(data.p, 6) # 6 cluster solution
# get cluster means
aggregate(data.p,by=list(fit$cluster),FUN=mean)
# append cluster assignment
data.p <- data.frame(data.p, fit$cluster)
# PLot Clusters
clusplot(data.p, fit$cluster, color=TRUE, shade=TRUE, labels=2, lines=0)
data.p <- data.frame(dat$PDB, data.p)
#print(data.p)
plot(data.p[,2],col=data.p$fit.cluster) # takes the RMSD column of data.p(by indexing) then colours the points defined by the clustering
par(xpd=NA)
legend(0,0, c("Group 1","Group 2", "Group 3", "Group 4", "Group 5", "Group 6", "Group 7"), pch=1, col=1:7)
write.matrix(data.p, file = "kmeans_output.txt", sep = " ")
输出如下所示:
我尝试使用以下方法更改 X 和 Y 值:
200,200
-200,200
200,-200
-200,-200