rearranging the x-axis

Hi I'm new to R and could use some help. Im supposed to check some data regarding credit defaults.
To see how defaults are for different ratings by moodys I did the following:

Default_pro_rating= CrossTable(ratg, def)
prozentualer_Ausfall_pro_Rating= Default_pro_rating$prop.row[,2]
barplot((prozentualer_Ausfall_pro_Rating),xlab = "Rating", ylab = "anteilige Ausfälle", axis.lty = 1, las=2)

This works quite well actually, however, it does not sort them by the right order of the ranking , which would be Aaa, Aa1,..., instead it does A1, A2,A3, Aaa,.....
Does anybody know how I can rearrange my x-axis, I´ve searched all day but nothing seams to work for my problem.

Could you please post the result of


It says that I´m a new user and therefore can´t upload attachements, I´m sorry.
But it looks like the plot on this page Using R: barplot with ggplot2 | R-bloggers,
just that the y-axis has 0.00, 0.05, 0.10 and the x-axis has A1, A2,A3, Aa1,..... which I want to rearrange, as mentioned to Aaa, Aa1,..... I hope this explenation helps and thank you for your response already.

Below are examples of making a bar plot with a named vector in the order that the elements are stored and in an order determined manually. I think that will work for your data.

#Invent some data with names
Ratings <- c(C=5 ,A=6, B=4)

#plot in the order given

#Set the plot order manually

Created on 2021-04-22 by the reprex package (v0.3.0)

You do not have to upload any thing to post the output of the dput command. For the vector I made in the above code, I can run

> dput(Ratings)
c(C = 5, A = 6, B = 4)

I can then copy the output and paste it between lines that contain three back ticks, ```, to get

c(C = 5, A = 6, B = 4)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.