-1

i have a Graph in R, im using ggplot, this is my code:

BreachTbl %>% 
          dplyr::filter(!(is.na(country))) %>%
          ggplot2::ggplot() +
          geom_bar(aes(x = country)) +
          xlab( "Country" ) + ylab( "Record Losses" ) + ggtitle( "Claims per Country" ) +
          coord_flip() +
          facet_grid(.~Dataset_type)+
          scale_x_discrete(limits = as.character(sort(unique(BreachTbl$country))))

my problem is that when i use coord_flip(), now ylabel is sort from Z to A, and i want to be A to Z, i have "United States" "europe" and "Asia", since top to bottom, and i want to be from A to Z, what can i modified in my code lo do this? i don´t want sort by bar size, and for that reason, for my case i can´t use

x=reorder(country, -value)

beacuse my problem is only in y label, my observations start in Z, when should be start in A

Regards

Carlos Tellez
  • 147
  • 1
  • 2
  • 10
  • Could you provide some sample data? This sort of problems are usually solved using some variation of fct_reorder – Henry Cyranka Nov 05 '18 at 23:03
  • Hi Carlos. Re-ordering bars in a barplot has been (gets) asked *a lot* around SO. Please take a look at the provided duplicate links; if there are still problems you should provide a minimal & reproducible code example including sample data. – Maurits Evers Nov 05 '18 at 23:29

1 Answers1

0

This behavior should not depend on coord_flip(). Try in aes

x = reorder(country, -value) 
paoloeusebi
  • 1,056
  • 8
  • 19