2017-04-19 5 views
1

ggplot2에 범주 형 x 축 변수의 연속 Y 축 값을 플롯하려하고 플립하려고 시도하지만 y 축 값이 올바르지 않습니다. 전시.ggplot2 뒤집힌 Y 축 막대가 올바르게 설정되지 않음

이는 내 데이터가 설정됩니다

       AIC.means AIC.lci AIC.uci 
Sparse Dual Stream   -4632.137 -4655.353 -4608.922 
Heterogeneous Dual Stream A -4627.653 -4650.866 -4604.439 
Heterogeneous Dual Stream B -4622.063 -4645.194 -4598.932 
Dense Dual Stream    -4616.507 -4639.633 -4593.381 
Radical Storage    -4615.934 -4639.052 -4592.817 
Radical Sparse Comp.   -4601.292 -4624.428 -4578.156 
Radical Heterogeneous Comp. B -4600.650 -4623.785 -4577.515 
Radical Dense Comp.   -4589.490 -4612.632 -4566.348 
Radical Heterogeneous Comp. A -4587.993 -4611.141 -4564.845 

이 음모 내가 생산 줄거리에 대한 코드입니다. 아래와 같이

enter image description here

ggplot(AIC.plotdata, aes(x=row.names(AIC.plotdata), y=AIC.means)) + 
    geom_bar(aes(), stat="identity") + 
    scale_y_continuous(limits = c(-4700, -4500)) + 
    coord_flip() 

는 I는 분 이하, 최고 상기 Y 축 제한을 설정. 따라서 y 축 레이블이 없으면 축 범위를 벗어나는 경우가있을 수 없습니다.

summary(AIC.plotdata$AIC.means) 
    Min. 1st Qu. Median Mean 3rd Qu. Max. 
    -4632 -4622 -4616 -4610 -4601 -4588 

이 내가 ggplot2에서 얻으려고하지만, lattice합니다 (AIC 값이 나는 아직 ggplot에 대해 알아낼 필요가 정렬 된 순서로 표시)를 사용하여 얻어진 것입니다.

enter image description here

나는 당신의 도움을 주셔서 감사합니다 것입니다!

+0

geom_bar이 한계에 영점이 범위 A는이 바닥 – Nate

+0

감사의 앵커 싶어! 데이터에 대한 흥미로운 차이가 -4700과 -4500 사이 인 경우이 제약 조건을 해결할 수있는 방법이 있습니까? 값은 모델 패널티를 나타내 므로 페널티가 낮을수록 모델이 좋으므로 부호를 뒤집는 것은 의미가 없습니다. –

+0

'geom_bar' 용어에서'aes()'없이 시도해보십시오. 이것은 ggplot에 미학이 없다는 것을 알려줄 수 있습니다. 따라서 빈 차트가됩니다. –

답변

1

geom_segement을 사용하고 ggplot 전화에서 데이터를 이동하는 방법에 대해 알려주세요. 비슷한 ggplot2: Setting geom_bar baseline to 1 instead of zero이 질문을 참조 :

ggplot(df) + 
    geom_segment(aes(x=rownames, xend=rownames, y=-4700, yend=AIC.means), size = 10) + 
    scale_y_continuous(limits = c(-4700, -4500)) + 
    coord_flip() 

enter image description here

데이터 :

df <- structure(list(rownames = c("Sparse Dual Stream", "Heterogeneous Dual Stream A", 
"Heterogeneous Dual Stream B", "Dense Dual Stream", "Radical Storage", 
"Radical Sparse Comp.", "Radical Heterogeneous Comp. B", "Radical Dense Comp.", 
"Radical Heterogeneous Comp. A"), AIC.means = c(-4632.137, -4627.653, 
-4622.063, -4616.507, -4615.934, -4601.292, -4600.65, -4589.49, 
-4587.993), AIC.lci = c(-4655.353, -4650.866, -4645.194, -4639.633, 
-4639.052, -4624.428, -4623.785, -4612.632, -4611.141), AIC.uci = c(-4608.922, 
-4604.439, -4598.932, -4593.381, -4592.817, -4578.156, -4577.515, 
-4566.348, -4564.845)), .Names = c("rownames", "AIC.means", "AIC.lci", 
"AIC.uci"), row.names = c(NA, -9L), class = "data.frame") 
+0

이것은 내가 필요한 것입니다. 정말 고맙습니다! –