I am plotting a table with the values below:
| No | Sector | Amount USD (million) |
|---|---|---|
| 1 | Air Pollution | 134 |
| 2 | Water Resources | 3,158 |
| 3 | Land Use and Land Use Change | 91 |
| 4 | Biodiversity | 74 |
| 5 | Agriculture | 2,386 |
| 6 | Industry and Commerce | 528 |
| 7 | Mining | 312 |
| 8 | Tourism | 252 |
| 9 | Energy | 262 |
| 10 | Transport | 1,071 |
| 11 | Disaster Risk Management and Human Settlements | 519 |
| 12 | Waste Management | 231 |
| 13 | Health | 52 |
| 14 | Gender; People Living With HIV and AIDS and other Vulnerable groups | 25 |
| 15 | Children and Youth | 32 |
| 16 | Capacity Building | 45 |
| 17 | Role of Meteorological Services | 23 |
| 18 | Technology Transfer | 574 |
| 19 | Climate Change Education | 15 |
| 20 | Public Awareness | 15 |
| 21 | Climate Change Governance | 88 |
Once done, I put in the following code in R studio
#reading the table into R studio
zim5 <- read_excel ('zimbabwe-climate-finance-excel4.xlsx', col_names = TRUE)
zim5
#creating the objects for easier typing
sector1 <- zim5$Sector
sector1
millions1 <- zim5$'Amount USD (million)'
millions1
#finally plotting the barplot with a legend
mycol <- colors()[444:500]
barplot(millions1~sector1, width = 4, space = 0.2, main = 'Zimbabwe budget by sector', xlab = 'Economic sectors', ylab = 'Amount in US $ millions',
col = mycol, cex.names = 0.6, horiz = F, las = 2)
legend('top', sector1, fill = mycol, cex = 0.7, text.font = 3)
My aim was to get a barplot with a legend. However, although I managed to create the barplot (including a different one with horizontal bars (horiz = T and las = 1), my legend always seems to display the text labels in a different order than in the barplot in both. i.e., Air pollution corresponds with the fill of Agriculture in the graphic and so on. 
Though I noticed R studio seems to balance out the position of the bars according to their heights or something, I want the legend labels to correspond with their appropriate fill colours like in the x axis of the plot, whether or not R studio orders the bars differently from the table.

