2013-05-07 9 views
5

ggplot2를 사용하여 모든 로그 값이 큰 데이터 (10^6에서 10^8 사이)의 선 그래프를 만들었습니다. 축이 0에서 시작하지 않기 때문에 "원점"에서 교차하지 않는 것이 좋습니다.축이 ggplot2에서 교차하지 못하도록하는 방법

ggplot2 plot

하나가 기본 그래픽에서 얻을처럼 좀 더 뭔가를 원합니다 (그러나 나는 또한 정말 ggplot2처럼 geom_ribbon과 다른 멋진 물건을 사용하고 있습니다 : 여기

는 축이 현재처럼 무엇 그래서)는 ggplot2의 해결책을 찾기 위해 선호하는 것 :

여기

non-intersecting axes

이야 내가 현재 뭘하는지 :

이 문제에 대한 691,363,210
mydata <- data.frame(Day = rep(1:8, 3), 
    Treatment = rep(c("A", "B", "C"), each=8), 
    Value = c(7.415929, 7.200486, 7.040555, 7.096490, 7.056413, 7.143981, 7.429724, 7.332760, 7.643673, 7.303994, 7.343151, 6.923636, 6.923478, 7.249170, 7.513370, 7.438630, 7.209895, 7.000063, 7.160154, 6.677734, 7.026307, 6.830495, 6.863329, 7.319219)) 

ggplot(mydata, aes(x=Day, y=Value, group=Treatment)) 
    + theme_classic() 
    + geom_line(aes(color = Treatment), size=1) 
    + scale_y_continuous(labels = math_format(10^.x)) 
    + coord_cartesian(ylim = c(6.4, 7.75), xlim=c(0.5, 8)) 

plot(mydata$Day, mydata$Value, frame.plot = F) #non-intersecting axes 
+0

그래서 당신은 더 아래 그래프처럼 뭔가 싶어? 당신은'geom_point' 또는'qplot'을 시도 할 수 있습니까? – Harpal

답변

3

해결 theme(axis.line=element_blank())로 축 라인을 제거하고 geom_segment()와 거짓 축 라인을 추가하는 것 - Y 축의 X 축 및 제 하나. x, y, xendyend 값은 플롯 (각각의 해당 축에 대해 플롯에 표시된 가장 작은 값과 가장 큰 값으로 취함)과 coord_cartesian()에 사용 된 축 제한으로 결정됩니다 (세그먼트가 중심선).

ggplot(mydata, aes(x=Day, y=Value, group=Treatment)) +theme_classic() + 
geom_line(aes(color = Treatment), size=1) + 
scale_y_continuous(labels = math_format(10^.x))+ 
coord_cartesian(ylim = c(6.4, 7.75), xlim=c(0.5, 8))+ 
theme(axis.line=element_blank())+ 
geom_segment(x=2,xend=8,y=6.4,yend=6.4)+ 
geom_segment(x=0.5,xend=0.5,y=6.5,yend=7.75) 

enter image description here

+0

완벽한, 고마워요! – phosphorelated

관련 문제