3 pièce(s) jointe(s)
Mes labels sont inversees dans un Geom Bar sous ggplot
Bonjour a tous,
Je doit faire un comptage des appels clients recus par des collegues Espagnols. J ai extrait toutes mes donnees en faisant une requete SQL importee sous RStudio avec un objet ODBC. Le dataframe que j obtiens me convient parfaitement.
Pièce jointe 541807
Je souhaite faire un graphique de type geom bar "stack" afin de montrer , mois par mois, le nombre d appel recu par l equipe espagnole et le nombre d appel recu par l equipe "non espagnole".
Ca marche tres bien (voir photo ci dessous) sauf pour les labels qui sont inverses: prenez en exemple la derniere colonne a droite et vous verrez que le "15" et le "55" sont inverses. J ai essaye pas mal de choses sans succes.
Pièce jointe 541821
Voici mon code (j ai active ggplot, Lubridate et plyr) , mon dataframe s appelle AggCountCallsPerLangOrd_SpanTeam :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
AggCountCallsPerLangOrd_SpanTeam_cumsum <- ddply(AggCountCallsPerLangOrd_SpanTeam, "YearAndMonth",transform, label_ypos=cumsum(NumberofCalls))
ggplot (AggCountCallsPerLangOrd_SpanTeam_cumsum, aes(x=YearAndMonth, y=NumberofCalls, fill=Team ))+
geom_bar(stat="identity" , width=20, position = 'stack')+ # identity means that both x and y values are from the dataframe
geom_text(aes(y=label_ypos , label=NumberofCalls, fill=Team), vjust=2, color="white", size=3)+ # to show the NumberofCalls on each column
#geom_text(aes(y=label_ypos , label=NumberofCalls, fill=Team), position = position_stack(reverse=TRUE, vjust=2), color="white", size=3)+ # to show the NumberofCalls on each column
scale_fill_brewer(palette="Paired")+
ggtitle ("Number of Calls per Year/Month received by the Spanish Team and the Non Spanish Team")+ # to show the title
theme (plot.title = element_text(colour="steelblue"))+ # to change the color of the title
theme (legend.position = "bottom")+ # to show the legend on the bottom
scale_x_date(date_breaks = "1 months" , date_labels= "%Y %m") + # to format the x axis for date
theme(axis.ticks.x = element_blank()) + # to remove the ticks on x axis
theme(axis.text.x = element_text(angle=45)) # to incline the labels at 45 degrees |
Merci de votre aide pour m aider a remettre les labels dans l ordre....
J ai modifie cette ligne:
Code:
1 2
|
geom_text(aes(y=label_ypos , label=NumberofCalls, fill=Team), position = position_stack(reverse=FALSE), color="white", size=3)+ |
Mes labels sont dans l ordre mais "au dessus" de leur colonnes respectives (on distingue le "15" et le "55" en dessus de leurs colonnes):
Pièce jointe 541845
On dirait que les bar plot et les labels n utilisent pas la meme echelle.
Une idee ?
c est bon ca fonctionne, Il fallait utiliser:
Code:
1 2
|
geom_text(aes(y=NumberofCalls , label=NumberofCalls, fill=Team), position = position_stack(reverse=FALSE), color="white", size=3, vjust=2)+ |
Merci quand meme.