0

I would like to create a stacked horizontal barchart that uses defined breaks in the stacks. I would also like this stacked barchart to use percentages rather than counts.

threat_status total species
LC             300    bird
VU             20     bird
EX             100    mammal
LC             0      bird
LC             100    bird

This is what I have so far:

bar3 <- ggplot(species_borders, aes(x = threat_status, fill = Total)) +  
  geom_bar(aes(y = (..count..)/sum(..count..))) +
  coord_flip +
  scale_y_continuous(labels=percent) +
  ylab("Percentage of species") +
  xlab("Threat status") +
  geom_col(position = "stack", width = 0.4) 
  scale_fill_discrete(name = "Borders crossed", breaks = c("3-300","2-1","0"), labels = c("3-300","2-1","0"))

This works, but doesn't show the breaks or colours.

My expected result would be staked barchart, with y-axis showing the percentage of species, x-axis is the threat_status, and the stakes are 3 different colours with breaks "0", "1-2", "3-300".

Brigadeiro
  • 2,649
  • 13
  • 30
  • Are you sure your column is called "Total", not "total" like in the printout you showed? It doesn't seem like the breaks you assigned would show up anywhere in this data. [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on posting an R example that's easy to help with – camille Aug 28 '19 at 03:19
  • 1
    Thanks, so I ended up adding an additional column showing the breaks I wanted. So all sorted. Cheers, M – Michelle Ward Aug 28 '19 at 04:09

0 Answers0