2013-05-17 3 views
0

각 플롯에 대해 다른 매개 변수를 사용하려면 facet_wrap을 사용하십시오. 아래의 예는 : 잘 작동ggplot2에서 facet_wrap 사용

x = c(43,22,53,21,13,53,23,12,32) 
y = c(42,65,23,45,12,22,54,32,12) 

df = cbind(x,y) 

df = as.data.frame(df) 

meany = mean(y) 

p = ggplot(df, aes(x=x,y=y, colour=(y > meany))) + 
     geom_point() + 
     geom_hline(yintercept = meany) 
p 

, Y의 평균값에 광고가 상기 포인트 라인 위와 아래 다른 색상이다.

필자는 각 요소 수준에서이 작업을 수행하고자하는 큰 데이터 프레임을 가지고 있으며 모든 플롯을 표시하기 위해 facet_wrap을 사용합니다. facet_wrap의 모든 그래프에서 ggplot의 색상 및 yintercept를 변경하는 방법을 모르겠습니다.

또한 플롯에 더 많은 레이어가 있어야합니다. 즉, 각 플롯이 다른 모델의 MSE를 비교합니다.

도움 주셔서 감사합니다.

+0

실제'data.frame'의 작은 하위 세트가 있습니까? http://docs.ggplot2.org/0.9.3.1/facet_wrap.html을 읽었습니까? 'p + facet_wrap (~ yourFactor)'가 이미 원하는 결과를 가져 왔습니까? 또한 http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example을 읽어보십시오. – Beasterfield

답변

2

이와 비슷한?

DB <- data.frame(F = factor(rep(LETTERS[1:3], each = 20)), 
       x = rnorm(60, 40, 5), 
       y = rnorm(60, 40, 5)) 

library(plyr) 
library(ggplot2) 

DB <- ddply(DB, "F", mutate, ind = y > mean(y)) 
mns <- ddply(DB, "F", summarise, meany = mean(y)) 

ggplot(DB, aes(x = x, y = y, color = ind)) + 
    geom_point() + 
    geom_hline(data = mns, aes(yintercept = meany)) + 
    facet_wrap(~ F, nrow = 1) 

마지막 요청이 너무 막연합니다 (즉, 컨텍스트가 부족합니다).