2017-09-05 5 views
1

gagplot2에서 "변경됨"이 "예"인 점이 빨간색 점이고, 나머지가 회색이고, "중요"가 "중요"인 점이 추가 점이있는 gplplot을 만들고 싶습니다 하숙 인은 녹색이고, 나머지는 회색 테두리가있다.ggplot2의 다중 피쳐 스 캐터 플롯

ggplot(df, aes(x = a, y = b)) + 
    geom_point(aes(col = Changed)) + 
    geom_point(aes(col = Significant)) + 
    scale_color_manual(values = c("green", "red","grey", "grey")) + 
    theme_bw(base_size = 12) + theme(legend.position = "bottom") 

입력 데이터 :이 일을

structure(list(a = c(4.31316551, 5.7663368, 2.49063318, 5.83090286, 
3.11188057, 9.58084417, 4.08696886, 3.11188057, 6.43800344, 1.77771123, 
4.22594833), b = c(0.848363512, 0.045492721, 0.049883076, 0.136202457, 
0.572585532, 0.175069609, 0.000782666, 0.848363512, 0.254619199, 
0.378181529, 0.848363512), Significant = structure(c(1L, 2L, 
2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L), .Label = c("no", "yes"), class = "factor"), 
    Change = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 
    1L, 1L), .Label = c("no", "yes"), class = "factor")), .Names = c("a", 
"b", "Significant", "Change"), class = "data.frame", row.names = c(NA, 
-11L)) 
+1

당신은 데이터 샘플을 추가 할 수 있습니다를 – MorganBall

+0

업데이트 버전을 참조하십시오하시기 바랍니다 여기 내 시도이다 – user2904120

답변

1

두 가지 방법 :

ggplot(data = df, mapping = aes(x=a,y=b)) + 
    geom_point(shape = 21, size=3, mapping = aes(fill=Change, color=Significant)) + 
    scale_fill_manual(values=c("grey", "red")) + 
    scale_color_manual(values=c("grey","green")) 

ggplot(data = df, mapping = aes(x=a,y=b)) + 
    geom_point(data=df[df$Significant == "no",], color="grey", size=5) + 
    geom_point(data=df[df$Significant == "yes",], color="green", size=5) + 
    geom_point(size=3, mapping = aes(color=Change)) + 
    scale_color_manual(values=c("grey","red")) 
+0

감사합니다. 첫 번째 질문을 좋아합니다. 한 번만 더 질문합니다. 세 번째 지정자가 있다고합니다. a는 4보다 커야하므로 색상이 적용됩니다. 그렇지 않으면 회색으로 유지됩니다. – user2904120

+0

계산 된 조건을 데이터 세트에 새 열로 추가하는 것이 좋습니다. –

관련 문제