2012-10-15 2 views
0

아래 이미지를 만들 때 ggplot2를 사용했습니다. facet_wrap의 개별면으로 테마 (외래, 경제 등)별로 데이터를 탐색 해보고 싶습니다. 나는 더 이상 레이블 (73 (1.02 %), 67 (.93 %) 등)을 바에 다시 둘 수 없다는 점을 제외하고는 원하는 모든 것을 재구성 할 수 있습니다. 라벨을 어떻게 그릴 수 있습니까? 여기 면 처리 된 물결 모양 바브 트에 geom_text 레이블

enter image description here

내 코드입니다 :

dat3 <- structure(list(grouping.var = structure(c(1L, 3L, 1L, 3L, 1L, 
    3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L), class = "factor", .Label = c("BIDEN", 
    "RADDATZ", "RYAN")), word.count = c(7240, 7153, 7240, 7153, 7240, 
    7153, 7240, 7153, 7240, 7153, 7240, 7153, 7240, 7153, 7240, 7153 
    ), variable = structure(c(4L, 4L, 2L, 2L, 1L, 1L, 5L, 5L, 3L, 
    3L, 7L, 7L, 6L, 6L, 8L, 8L), .Label = c("foreign", "economic", 
    "rebublican_people", "health", "democratic_people", "romney", 
    "obama_any_name", "obama_by_name"), class = "factor"), value = c(29, 
    36, 27, 47, 67, 73, 13, 28, 45, 24, 13, 20, 26, 21, 1, 14), labs = c("29(.0040)", 
    "36(.0050)", "27(.0037)", "47(.0066)", "67(.0093)", "73(.0102)", 
    "13(.0018)", "28(.0039)", "45(.0062)", "24(.0034)", "13(.0018)", 
    "20(.0028)", "26(.0036)", "21(.0029)", "1(.0001)", "14(.0020)" 
    ), loc = c(22.5, 29.5, 20.5, 40.5, 60.5, 65.75, 6.5, 21.5, 38.5, 
    17.5, 6.5, 13.5, 19.5, 14.5, 7, 7.5), cols = c("black", "white", 
    "white", "white", "white", "white", "white", "white", "white", 
    "white", "white", "white", "white", "white", "white", "white" 
    )), .Names = c("grouping.var", "word.count", "variable", "value", 
    "labs", "loc", "cols"), row.names = c(NA, -16L), class = "data.frame") 


ggplot(dat3, aes(x=variable, y=value, fill=grouping.var)) + 
    geom_bar(position="dodge", stat="identity") + 
    coord_flip() + theme_bw() + 
    theme(legend.position="top", legend.background = element_rect(color="white"), 
     panel.grid.major=element_blank(),panel.grid.minor=element_blank(), 
     legend.title=element_blank(), axis.ticks.y = element_blank(), 
     axis.text.y = element_blank()) + 
    ylab("") + xlab("") + facet_wrap(~variable, ncol=2, scales = "free_x") + 
    scale_fill_manual(values=c("#0000FF", "#FF0000"), 
     guide = guide_legend(reverse=TRUE)) 
    geom_text(aes(label = labs, y = loc, x = variable), 
       size = 5, position = position_dodge(width=0.9), color=dat3$cols) 

답변

2

나는 color=dat3$cols 제거있어하고,

ggplot(dat3, aes(x=variable, y=value, fill=grouping.var)) + 
    geom_bar(position="dodge", stat="identity") + 
    coord_flip() + theme_bw() + 
    theme(legend.position="top", legend.background = element_rect(color="white"), 
     panel.grid.major=element_blank(),panel.grid.minor=element_blank(), 
     legend.title=element_blank(), axis.ticks.y = element_blank(), 
     axis.text.y = element_blank()) + 
      ylab("") + xlab("") + facet_wrap(~variable, ncol=2, scales = "free_x") + 
      scale_fill_manual(values=c("#0000FF", "#FF0000"), 
          guide = guide_legend(reverse=TRUE))+ 
geom_text(aes(label = labs, y = loc, x = variable), 
      size = 5, position = position_dodge(width=0.9)) 

enter image description here

+0

흥미 롭습니다. dev에 감사드립니다. 버전이 차이가 없습니다. +1 –

+0

재미 있습니다. github 페이지에서 문제를 제기 할만한 가치가 있습니다. – mnel

+0

dev 버전을 제거한 후 dev 버전을 다시 설치하여 오류를 다시 작성한 후 dev를 재설치하는 것처럼 보일 수 없습니다. 번역. 내가 "0.9.2.99"를 다시 설치할 때까지 문제를 게시하기 위해 기다릴 것입니다. –

0

내가 유사한 문제가 발생하여 작업을 표시하지 정말 버그. 하지만 잘

당신의 해킹처럼

을 문서화 "나는 color=dat3$cols 제거있어 작동 보인다"자세하게 (AES를 해석 할 수있는 일의 모든 색상 값을 지정하는 솔루션이다

을하지 색상 = foo는) 내 경우

, 나는 ggplot에서 AES(),()와 geom_text()

1) ggplot(dat_foo, aes(x=xfoo_i, y=yfoo, colour=colourfoo, group=groupfoo))

두 통화를했다

2) geom_text(data = label_data,aes(x = xfoo, y = yfoo, label=label_foo,colour=NULL)

관련 문제