2014-01-25 4 views
1

다이아몬드 데이터 세트와 다음 코드를 사용하여 아래 그림을 만들었습니다. 여러 ggplot 범례의 레이블 변경

ggplot(diamonds[diamonds$color == c("D", "E", "F"),], aes(x=carat, y=price, shape = color, color=cut)) + 
    geom_point() 

enter image description here

나는 그들이 현재보다 다른 뭔가 전설 라벨 (안 제목)을 변경하려합니다.

나는 하나의 전설

ggplot(diamonds[diamonds$color == c("D", "E", "F"),], aes(x=carat, y=price, shape = color, color=cut)) + 
    geom_point() + 
    scale_shape_manual(lables = c("DDD", "EEE", "FFF")) 

에 대한 코드를 (아래) 시도하지만이 오류를 얻을 수있다 : 두있을 때

Error in discrete_scale(aesthetic, "manual", pal, ...) : 
    unused argument (lables = c("DDD", "EEE", "FFF")) 

어떻게 변경 될 수있는 전설을 지정합니까를?

감사

답변

2

또는 당신은 lables 오류를 일으키는 대신 라벨 당신의 오타 참고 각 레벨

diamonds2 <- diamonds[diamonds$color == c("D", "E", "F"),] 
diamonds2$color <- factor(diamonds2$color, levels = c('D', 'E', 'F'), labels = c("DDD", "EEE", "FFF")) 

ggplot(diamonds2, aes(x=carat, y=price, shape = color, color=cut)) + 
    geom_point() 
3

당신이 scale_shape_manual에뿐만 아니라 values을 전달하는 경우 범례 레이블을 변경할 수 있습니다. enter image description here

3

의 레이블을 변경하는 요소를 사용할 수 있습니다

ggplot(diamonds[diamonds$color == c("D", "E", "F"),], aes(x=carat, y=price, shape = color, color=cut)) + geom_point() + 
    scale_shape_manual(values=1:3, 
         labels=c("CCC", "DDD", "EEE")) 

을 생성합니다. 시도해보십시오.

scale_shape_discrete(labels = c("DDD", "EEE", "FFF"))