2017-04-05 12 views
0

** 말 그대로 수평이 필요로 할 때 아래는 측면, 그룹화 바 플롯을 회전

나는 음모를 만든 업데이트하지만 coord_flip() 대신 왼쪽에 중첩기를 갖는 하단의 측면을 떠난다.

데이터 :

srvc_data <- structure(list(dept = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("Distribution Centre Services", 
"IT", "Marketing", "Merchandise & Inventory", "Operations and Communication" 
), class = "factor"), label = c("test5", "test7", "test3", "test10", 
"test4", "test6", "test2", "test1", "test11", "test12", "test9", 
"test8", "test18", "test19", "test15", "test17", "test13", "test16", 
"test20", "test14", "test22", "test21", "test25", "test23", "test24", 
"test27", "test26", "test28", "test29", "test31", "test33", "test30", 
"test32", "test38", "test36", "test37", "test43", "test34", "test35", 
"test40", "test39", "test42", "test41", "test5", "test7", "test3", 
"test10", "test4", "test6", "test2", "test1", "test11", "test12", 
"test9", "test8", "test18", "test19", "test15", "test17", "test13", 
"test16", "test20", "test14", "test22", "test21", "test25", "test23", 
"test24", "test27", "test26", "test28", "test29", "test31", "test33", 
"test30", "test32", "test38", "test36", "test37", "test43", "test34", 
"test35", "test40", "test39", "test42", "test41"), Gap = c(-0.07, 
-0.13, -0.15, -0.16, -0.16, -0.21, -0.22, -0.24, -0.24, -0.25, 
-0.3, -0.3, -0.18, -0.19, -0.24, -0.29, -0.3, -0.34, -0.36, -0.41, 
-0.46, -0.63, -0.16, -0.18, -0.21, -0.22, -0.27, -0.29, -0.31, 
-0.31, -0.35, -0.39, -0.42, -0.15, -0.15, -0.2, -0.21, -0.22, 
-0.27, -0.29, -0.29, -0.31, -0.36, -0.07, -0.13, -0.15, -0.16, 
-0.16, -0.21, -0.22, -0.24, -0.24, -0.25, -0.3, -0.3, -0.18, 
-0.19, -0.24, -0.29, -0.3, -0.34, -0.36, -0.41, -0.46, -0.63, 
-0.16, -0.18, -0.21, -0.22, -0.27, -0.29, -0.31, -0.31, -0.35, 
-0.39, -0.42, -0.15, -0.15, -0.2, -0.21, -0.22, -0.27, -0.29, 
-0.29, -0.31, -0.36), impeff = structure(c(1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L), .Label = c("Importance", "Effectiveness"), class = "factor"), 
    score = c(0.87, 0.79, 0.78, 0.82, 0.81, 0.81, 0.92, 0.92, 
    0.78, 0.81, 0.86, 0.91, 0.79, 0.79, 0.87, 0.93, 0.9, 0.9, 
    0.82, 0.95, 0.91, 0.95, 0.77, 0.79, 0.82, 0.8, 0.83, 0.9, 
    0.91, 0.94, 0.89, 0.94, 0.91, 0.82, 0.74, 0.78, 0.81, 0.83, 
    0.85, 0.82, 0.81, 0.8, 0.83, 0.8, 0.66, 0.63, 0.66, 0.65, 
    0.6, 0.7, 0.68, 0.54, 0.56, 0.56, 0.61, 0.61, 0.6, 0.63, 
    0.64, 0.6, 0.56, 0.46, 0.54, 0.45, 0.32, 0.61, 0.61, 0.61, 
    0.58, 0.56, 0.61, 0.6, 0.63, 0.54, 0.55, 0.49, 0.67, 0.59, 
    0.58, 0.6, 0.61, 0.58, 0.53, 0.52, 0.49, 0.47)), row.names = c(NA, 
-86L), .Names = c("dept", "label", "Gap", "impeff", "score"), class = "data.frame") 

그리고 코드 :

(플립없이) 줄거리는 다음과 같습니다

, 나는 그것을 필요로

ggplot(data = srvc_data, aes(x = label, y = score)) + 
    geom_bar(aes(fill = impeff),stat = "identity", position = "dodge",width = 1) + 
    facet_grid(~dept, switch = "x", scales = "free", space = "free") + 

    #coord_flip()+ 
맨 왼쪽에있는면 종류와, 수평 . coord_flip()은 어떻게 작동합니까? 왜 그것은 패싯 스트립을 뒤집거나 움직이지 않는가? 쌓아 올린 서식을 무시하십시오!

enter image description here

** UPDATE 데이터의 순서를 전환하여 내가 줄거리를 해결 한 @neilfws하는 그래서 감사합니다.

ggplot(data = srvc_data, aes(x = label, y = score)) + 
    geom_bar(aes(fill = impeff),stat = "identity", position = "dodge",width = 1) + 
    facet_grid(dept~., switch = "y", scales = "free_y", space = "free") + 
    coord_flip() 

이제 올바른 방향의 플롯을 만들었지 만 각면에 사용되지 않은 모든 레이블에는 사용되지 않은 공간이 많이 있습니다. facet_grid 호출 내에서 scales = "free" 설정은 작동하지 않으며 drop = T도 아닙니다. 어떤 아이디어? 아래 도표를 참조하십시오. 당신 coord_flip, 당신은 또한 페이스 팅 관계 (~)를 반대해야하는 경우

enter image description here

답변

1

는 y 축에 배치하는 측면에 배치하고, switch합니다. 이게 당신이 원하는 것에 가깝게합니까?

ggplot(srvc_data, aes(label, score)) + 
    geom_bar(aes(fill = impeff), stat = "identity", position = "dodge", width = 1) + 
    facet_grid(dept ~ ., switch = "y", scales = "free", space = "free") + coord_flip() 
+0

아하, 이제 알겠습니다. 고마워! 제가 각면에서 사용하지 않은 라벨을 무시하는 방법이 있습니까? "free.y"를 지정하겠다고 생각했지만 "무료"이외의 다른 것을 사용하면 오류가 발생합니다. 편집 : 저울과 공간 호출이 패싯에서 어떻게 작동합니까? – Alex

+0

'free'는'free_y'와 같은 효과가 있다고 생각합니다. ('.'이 아니라 밑줄이 있습니다). – neilfws

+0

위의 업데이트 된 질문에 대한 아이디어가 있으십니까, Neil? – Alex