2017-02-08 1 views
3

내 주요 목표는 내 플롯에서 요소를 다르게 색칠하는 것입니다. 내가 대신 내 specified 색상의 enter image description here : 나는 위의 코드를 실행할 때, 내가 출력으로이 얻을ggplot에 맞춤 색상 추가

mtcars$color[mtcars$carb = 4] = '#F98866' 
mtcars$color[mtcars$carb = 3] = '#68829E' 
mtcars$color[mtcars$carb = 2] = '#FF420E' 
mtcars$color[mtcars$carb = 1] = '#89DA59' 

p <- ggplot(mtcars) + 
    geom_point(aes(wt, mpg, 
        size = disp, 
        color = mtcars$color))# + scale_color_manual(values = mtcars$color) 

이렇게하려면 I manuallycategory에 대해 원하는 색상으로 여분의 열을 추가 사전 설정 ggplot 색을 얻으십시오.

마지막 줄의 주석 처리를 제거하면 I 부분적으로을 얻습니다. 원하는 색상 만 표시합니다.

어떻게이 문제가 해결 될 수 enter image description here ?

+0

'+ scale_color_identity()'? (단지'color = color'를 사용하고'aes'는'$'를 사용하지 마십시오.) – Axeman

+0

@Henrink what 무엇을 범위에 따라 색칠하고 싶지 않습니까? 그럼 뭐야? 값을 기준으로 색상을 지정한다고 가정 해 보겠습니다. '1 = 적색','2 = 청색'등 ... – Jack

+0

@Axeman 답을 쓸 수 있습니까? 따라갈 지 모르겠습니다. – Jack

답변

1
ggplot(mtcars) + 
    geom_point(aes(wt, mpg, size = disp, color = color)) + 
    scale_color_identity(guide = 'legend') 

enter image description here

+0

@ 간단하고 작습니다. 너는 내 graditute있어 – Jack