2013-03-19 5 views
4

scale_y _... (breaks = c (x1, x2)) 함수를 사용하지 않고 플롯에서 나누기를 설정하는 방법을 찾고있었습니다. 문제는 다음과 같습니다. 상자 플롯을 원합니다.ggplot2에서 scale_y_continuous()없이 중단

require(ggplot2) 
    a <- rnorm(10, 0, 5) 
    a <- as.data.frame(a); colnames(a) <- "test" 

    ### original boxplot 
    ggplot(data=a, mapping=aes(y=test, x=rep(1,10))) + 
     geom_boxplot() 

    ### scale_y_continous() cuts of my data points and changes the boxplot! 
    ggplot(data=a, mapping=aes(y=test, x=rep(1,10))) + 
     geom_boxplot() + 
     scale_y_continuous(limits=c(-1,1), breaks=c(-1,0,1)) 

    ### I am therefore using coord_cartesian() but I am missing a breaks() function 
    ggplot(data=a, mapping=aes(y=test, x=rep(1,10))) + 
     geom_boxplot() + 
     coord_cartesian(ylim = c(-1,1)) # + 
    # breaks(c(-1,0,1)) # something like this 

도움 주셔서 감사합니다.

+1

왜 궁금한데 왜 박스 플롯을 확대하고 싶습니까? – Arun

+0

확대/축소에 대해서는별로 중요하지 않지만 일렬을 나란히 배치 한 여러 개의 상자 그림에 대해 일정하게 유지하는 것이 중요합니다. –

+0

그런 경우,'log-scale' (또는)'facet'을'scales = "free"'와 사용하는 것이 더 낫습니다. – Arun

답변

14

coord_cartesian()scale_y_continuous()을 한 줄로 조합 할 수 있으며 축척 기능에서 limits=c(-1,1) 만 제거하면됩니다. scale 함수 내에서 limits=을 사용하면 데이터가 그 디 아apason에서 서브 세트됩니다. coord_cartesian()은 그 값 영역을 확대/축소합니다.

ggplot(data=a, mapping=aes(y=test, x=rep(1,10))) + 
     geom_boxplot() + 
     coord_cartesian(ylim = c(-1,1))+ 
     scale_y_continuous(breaks=c(-1,0,1)) 
+0

아! 감사합니다! 내가 ylim와 함께 그 일을하려고했다 (C (,)) + scale_y_continuous (나누기 = C를 (,)) 그러나 오류 메시지를 받았습니다 : 'Y'에 대한 규모가 이미 존재합니다. 'y'에 다른 눈금을 추가하면 기존 눈금을 대체합니다. 버전이 정상적으로 작동합니다. –