0

I am trying to create a faceted balloon plot using the ggpubr package in R. However the x-axis and Yaxis automatically get sorted in alphabetic order as shown in the image link. I want the X-axis level order to be "B" "A" "D" "C" "E" in the final plot instead of "A" "B" "C" "D" "E". Please give me some suggestions.

enter image description here

library (readxl)
library(ggpubr)
obs=read_excel("baloon plot.xlsx",sheet = "Sheet2")
my_cols <- c("#0D0887FF", "#6A00A8FF", "#B12A90FF",
             "#E16462FF", "#FCA636FF", "#F0F921FF")
ggballoonplot(as.data.frame(obs), x = "Location", y = "Season",
              size = "NSE", fill = "NSE")+
  gradient_fill(c("blue", "white", "red"))+facet_wrap("Model")+
  guides(size = FALSE)+
  theme_gray() +
  theme(text=element_text(family="Times New Roman", face="bold", size=14, color = "black"))+
  scale_y_discrete(name = "Season") +
  scale_x_discrete(name = "Location")
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • Provide the data in `dput()` format. Please visit [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – UseR10085 Dec 09 '20 at 07:14
  • 1
    Run `obs$Location <- factor(obs$Location, c("B", "A", "D", "C", "E"))` and then plot again. – Ronak Shah Dec 09 '20 at 07:27
  • See also these https://stackoverflow.com/questions/50755312/x-axis-with-more-than-one-factor-groups-ggplot & https://stackoverflow.com/questions/52214071/how-to-order-data-by-value-within-ggplot-facets. I would sort the seasons by water year order too – Tung Dec 09 '20 at 07:40
  • @RonakShah the command is not working in ggpubr package – coder_1 Dec 09 '20 at 13:07
  • Please add data using `dput` or something that we can copy and use. Also show expected output for the data shared. Read about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and [how to give a reproducible example](http://stackoverflow.com/questions/5963269). – Ronak Shah Dec 09 '20 at 13:22

0 Answers0