2017-04-07 2 views
1

오늘 제 세 번째 질문입니다. 덕분에 많은 것을 배웠습니다.패싯 내의 그룹화 된 막대 그림의 순서 바꾸기

curr.data$Gap 변수를 사용하여 각 패싯 내의 막대 그룹을 재정렬하려고합니다. 간격은 각 y 레이블에 대한 막대 사이의 차이이며 가장 작은 간격에서 가장 큰 간격으로 이동하려면 각 패싯 내에서 순서가 필요합니다.

내부 주문 순서를 고려해야하므로 다른 재주문 관련 질문과 약간 다릅니다.

일반적으로 설정 수준으로 데이터를 인수 분해하여 간단한 막대 그림에 대해이 작업을 수행 할 수 있지만 여기서 그 작업을 수행 할 수는 없습니다.

데이터 :

structure(list(dept = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 
1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 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("test 25", "test 23", "test 24", 
"test 27", "test 26", "test 28", "test 29", "test 31", "test 33", 
"test 30", "test 32", "test 38", "test 36", "test 37", "test 43", 
"test 34", "test 35", "test 40", "test 39", "test 42", "test 41", 
"test 25", "test 23", "test 24", "test 27", "test 26", "test 28", 
"test 29", "test 31", "test 33", "test 30", "test 32", "test 38", 
"test 36", "test 37", "test 43", "test 34", "test 35", "test 40", 
"test 39", "test 42", "test 41"), Gap = c(-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.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), section = c(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), impeff = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L), .Label = c("Effectiveness", "Importance"), class = "factor"), 
    score = c(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.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)), .Names = c("dept", "label", "Gap", "section", 
"impeff", "score"), row.names = c(23L, 24L, 25L, 26L, 27L, 28L, 
29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 
42L, 43L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 
77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L), class = "data.frame") 

코드 :

curr.plot <- ggplot(data = curr.data, aes(x = label, y = score)) + 
    geom_bar(aes(fill = impeff),stat = "identity", position = "dodge",width = .7) + 
    geom_text(aes(label=percent(score),group=impeff), position= position_dodge(width=.7),vjust=.4,hjust=-.1) + 
    facet_grid(dept~., switch = "y", scales = "free_y", space = "free") + 
    theme(legend.position = "bottom")+ 
    coord_flip()+ 
    guides(fill = guide_legend(reverse=TRUE,title=NULL))+ 
    theme(axis.title.x = element_blank()) + 
    theme(axis.title.y = element_blank()) + 
    theme(axis.text.y = element_text(colour="black"))+ 
    theme(strip.text.y = element_text(size = 12, colour = "black"))+ 
    scale_y_continuous(labels=percent,limits = c(0,1)) 

전류 출력 : enter image description here

답변

1

x = reorder(label,Gap)

x = label 교체
관련 문제