2017-03-09 3 views
2

에 두 전설 중 하나를 제거하려면 어떻게 나는 다음과 같은 코드가 있습니다난 그냥 GGPLOT

library(ggplot2) 

df  <- data.frame(iris)     # iris dataset 
pca <- prcomp(df[,1:4], retx=T, scale.=T) # scaled pca [exclude species col] 
scores <- pca$x[,1:3]      # scores for first three PC's 

# k-means clustering [assume 3 clusters] 
km  <- kmeans(scores, centers=3, nstart=5) 
ggdata <- data.frame(scores, Cluster=km$cluster, Species=df$Species) 

# stat_ellipse is not part of the base ggplot package 
source("https://raw.githubusercontent.com/tidyverse/ggplot2/master/R/stat-ellipse.R") 


ggplot(ggdata) + 
    geom_point(aes(x=PC1, y=PC2, color=factor(Species)), size=5, shape=20) + 
    stat_ellipse(aes(x=PC1,y=PC2,fill=factor(Species)), 
       geom="polygon", level=0.95, alpha=0.2) + 
    guides(color=guide_legend("Species"),fill=guide_legend("Cluster")) 

이 생산 : 어떻게 그냥를

enter image description here

그 사진에 명시된 바와 같이 할 '클러스터'범례를 제거 하시겠습니까?

답변

4

은 FALSE

ggplot(ggdata) + 
    geom_point(aes(x=PC1, y=PC2, color=factor(Species)), size=5, shape=20) + 
    stat_ellipse(aes(x=PC1,y=PC2, fill=factor(Species)), 
          geom="polygon", level=0.95, alpha=0.2)+ 
    guides(color=guide_legend("Species"), fill = FALSE) 
fill 가이드를 설정