I have a graph that contains airline names I would like to sort them alphabetically (reverse the current order).
here is my code. I tried creating a sorted column then I plotted it, but it didn't work.
#joining the two files
joinflights<-merge(delayed_flights,total_flights,by='airline')%>%
mutate(sorted_airline = fct_relevel(airline, "AirTran Airways Corporation","Alaska Airlines Inc.","American Airlines Inc.","Delta Air Lines Inc.",
"Endeavor Air Inc.","Envoy Air","ExpressJet Airlines Inc.","Frontier Airlines Inc.","Hawaiian Airlines Inc.",
"JetBlue Airways","Mesa Airlines Inc.","SkyWest Airlines Inc.","Southwest Airlines Co.","United Air Lines Inc.",
"US Airways Inc.","Virgin America"))
#creating a new variable to calculate the delay rate per airline
#creating a bar chart
airlines<-ggplot(joinflights%>%mutate(delay_rate=(count.x/count.y))
,aes(x= sorted_airline,y=delay_rate
))+
#adding a title and renaming the axises
labs(title="Flights Delay Rates by Airline",
x="Airline",y="Flights Delay Rate")+
#displayin y axis in percentage
scale_y_continuous(labels = percent)+
#adding a bar chart
geom_bar(stat = "identity")+
#flipping the graph to a horizntal view
coord_flip()
Thanks