dati da dbv:ordine inverso dopo coord_flip in R
gender Sektion
1 m 5
2 m 5
3 w 3B
4 w 3B
5 w 3B
6 m 4
Ho il seguente grafico:
Sekplot <- ggplot(dbv,aes(x=Sektion,
fill=factor(gender),
stat="bin",
label = paste(round((..count..)/sum(..count..)*100), "%")))
Sekplot <- Sekplot + geom_bar(position="fill")
Sekplot <- Sekplot + scale_y_continuous(labels = percent)
Sekplot <- Sekplot + labs(title = "test")
Sekplot <- Sekplot + scale_fill_discrete(name="test", breaks=c("m", "w", "k.A."), labels=c("m", "w", "k.A."))
Sekplot <- Sekplot + geom_hline(aes(yintercept = ges, linetype = "test"), colour = "black", size = 0.75, show_guide = T)
Sekplot <- last_plot() + coord_flip()
Sekplot <- Sekplot + guides(colour = guide_legend(override.aes = list(linetype = 0)),
fill = guide_legend(override.aes = list(linetype = 0)),
shape = guide_legend(override.aes = list(linetype = 0)),
linetype = guide_legend()) + theme(legend.title=element_blank())
Sekplot
uscita:
Plot with y-axis in wrong order
Come posso invertire il ordine dell'asse "Sektion"? Mi piacerebbe averne uno sopra e 8 in basso.
ho cercato, secondo GroupA $ Data < - Fattore (GroupA $ Date, livelli = giri (unica (GroupA $ Date))):
Sekplot <- last_plot() + coord_flip() + scale_x_reverse()
in vari gusti, ma non riusciva a trovare il giusta direzione.
Hai bisogno di qualcosa di simile a 'scale_x_discrete (limiti = REV (livelli (dat $ sektion)))' - vedi [questa risposta] (http://stackoverflow.com/a/7310754/2461552) – aosmith
Grazie mille, ha funzionato come un fascino! Non posso contrassegnare questa domanda come risolta, perché la risposta è in un commento. –
Non l'avevo messo come risposta perché stavo cercando di trovare i duplicati. Non ho trovato una corrispondenza davvero buona, quindi aggiungerò come risposta. – aosmith