stat_summary()
을 사용하면 depth
의 합계로 y
값의 위치를 계산하고 geom="text"
을 사용하여 레이블을 추가 할 수 있습니다. 막대에 각 cut
값의 depth
값의 합이 표시되므로 합계가 사용됩니다.
바와 같이 stat="identity"
이 바의 overploting을로 인한 문제를 만들기 때문에 y 값의 합계를 표시하는 대신 geom_bar()
의 stat_summary()
를 사용하는 것이 더 낫다 @joran에 의해 제안 음의 값이 될 경우 다음 줄이 음모의 부정적인 부분에 시작되며, 긍정적 인 부분으로 끝남 - 결과는 실제 값의 합이 아닐 것입니다.
ggplot(diamonds[1:100,], aes(x = cut, y = depth)) +
facet_wrap(~ color) +
stat_summary(fun.y = sum, geom="bar", fill = "blue", aes(label=cut, vjust = 0)) +
stat_summary(fun.y = sum, geom="text", aes(label=cut), vjust = 0)
또한 미리 계산 깊이 값의 합은 당신이 stat="identity"
및 geom_text()
와 geom_bar()
를 사용할 수 있습니다.
library(plyr)
diamonds2<-ddply(diamonds,.(cut,color),summarise,depth=sum(depth))
ggplot(diamonds2,aes(x=cut,y=depth))+
geom_bar(stat="identity",fill="blue")+
geom_text(aes(label=cut),vjust=0,angle=45,hjust=0)+
facet_wrap(~color)
http://stackoverflow.com/questions/10112587/re-alignment-of-numbers-on-the-individual-bars-with-ggplot2 – Ananta
@jrara의 중복 가능성 난이이 일을 알고 있다면 최종 버전, 나는 플롯을 내보내고 발행인과 같은 프로그램에 주석을 달았습니다. – user1738753