2012-10-17 7 views
0

K- 평균 클러스터링을 사용하여 일부 값을 클러스터링했습니다. 3 개의 그래프를 그려서 제 3의 그래프에 대한 전설을 원합니다. 범례를 그리기 위해 lengend() 함수를 사용했지만 범례가 플롯 (이미지 참조)에 나타나지 않고 오류가보고되지 않습니다. 같은K-Means 클러스터링에서 범례가 표시되지 않음

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 값을 시도

enter image description here

다음

200,200 
-200,200 
200,-200 
-200,-200 

답변

1

시도 :

legend("bottomleft", legend = paste("Group", 1:7), pch=1, col=1:7) 

y 축의 눈금을 확인하십시오. legend()에 전달하는 두 번째 좌표는 플롯의 경계 내에 있어야합니다. 0-200 모두와 200

당신이이 일을 생각하고 싶지 않은 경우 그림 3의 한계를 넘어 (방법)이다, 위치를 정의하는 문자의 사용은 훨씬 더 직관적이다. 제공 할 수있는 문자 위치에 대한 자세한 내용은 ?legend을 참조하십시오.