I have created the below data frame and want to create a stacked bar chart showing the percentages of available habitats (main.Avail
) alongside the percentage of used habitats (main.Used50K
). I have used the barplot(as.matrix(subset))
function but I can't seem add legends indicating the different habitat categories (NA
, BOG
, F
, OIP
, RG
, RIP
, UM
) in the stacked bar charts. How can I do this?
main.Hab main.Avail main.Used50K
1 <NA> 4.186001 0.7795595
2 BOG 8.128698 1.4224366
3 F 12.294499 0.4780462
4 OIP 43.902867 69.9860934
5 RG 7.488637 2.3009635
6 RIP 9.713074 22.7798587
7 UM 14.286223 2.2530800