私はRとggplot2で夜を過ごし、欲しいものを手に入れました:)
library('ggplot2')
library('plyr')
library('RColorBrewer')
library(scales)
label_positions<- function(x) {
n<-length(x)
wynik<-numeric(n)
for (i in 1:n){
if (i==1) {
wynik[i]<-0+x[i]/2
}
else {
wynik[i]<-x[i]-(x[i]-x[i-1])/2
}
}
return(wynik)
}
exam1<-ddply(example,.(GroupingVar,FacetVar,VarOfInterest), 'nrow')
exam1.1<-ddply(example,.(GroupingVar,FacetVar),summarise, sr=mean(as.numeric(VarOfInterest),na.rm=T),
odch=sd(as.numeric(VarOfInterest,na.rm=T)))
exam1<-merge(exam1,exam1.1,by.x=c('GroupingVar','FacetVar'),by.y=c('GroupingVar','FacetVar'))
names(exam1)[4]<-'Count'
exam2<-mutate(exam1,cumul=ave(Count,list(GroupingVar,FacetVar),FUN=cumsum),
N=ave(cumul, list(GroupingVar,FacetVar),FUN=max),
CumSumPercent=cumul/N*100,
Freq=Count/N*100)
exam2<-mutate(exam2,cfrq = ave(CumSumPercent, list(GroupingVar,FacetVar), FUN = label_positions))
exam2$XLabel<-paste(exam2$GroupingVar,' (N=',exam2$N,')',sep='')
exam2$PosMean<-105
p<-ggplot(exam2, aes(x = Etykieta, y = Freq, fill = VarOfInterest)) +
geom_bar(stat = 'identity',colour="black") +
labs (x = "", y = "Percentage", fill=" ") +
scale_fill_brewer(name="Rating", palette="Greens", breaks = rev(levels(exam2$VarOfInterest))) +
geom_text(aes(y = cfrq, label=paste(sprintf("%.01f",Freq), "%", sep='')), size=5) +
geom_text(aes(y=PosMean,label=paste(sprintf("%.02f",sr),' (',sprintf("%.02f",odch),')',sep='')),size=5)+
facet_wrap(~FacetVar,ncol=1) +
coord_flip() + ylab('Procent odpowiedzi') +
guides(fill=guide_legend(title=NULL)) + theme_bw() +
theme(legend.position="bottom",strip.text.x=element_text(size=15,face='bold'),
axis.text.x =element_text(size=12,face='bold'), axis.text.y =element_text(size=12,face='bold'),
axis.title.x=element_text(size=15,face='bold'), axis.title.y=element_text(size=15,face='bold'),
strip.background=element_rect(colour='black'))
plot(p)
そして結果