如何创建具有特定堆栈中断的堆栈图表?

时间:2019-08-28 01:51:00

标签: r ggplot2 stacked-chart

我想创建一个堆叠的水平条形图,该条形图使用堆叠中定义的中断。我也希望这张堆叠的条形图使用百分比而不是计数。

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

这是我到目前为止所拥有的:

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"))

这有效,但不显示断点或颜色。

我的预期结果是放样条形图,其中y轴显示物种的百分比,x轴表示Threat_status,并且这些桩是3种不同的颜色,其中包括“ 0”,“ 1-2”,“ 3-” 300“。

0 个答案:

没有答案