R 如何绘制一个表示数量比率的填充条形图?

R 如何绘制一个表示数量比率的填充条形图?,r,ggplot2,geom-bar,R,Ggplot2,Geom Bar,在RStudio中,我有以下数据帧: Month Faves Retweets Total 1. 2019-09 1267.0000 423.0000 1690.000 2. 2019-10 720.7819 294.8349 1015.617 3. 2019-11 741.2318 312.8748 1054.107 4. 2019-12 734.6458 314.0186 1048.664 5. 2020-01 754.9029 328.4743 1083.377 6.

在RStudio中,我有以下数据帧:

   Month   Faves     Retweets Total
1. 2019-09 1267.0000 423.0000 1690.000
2. 2019-10 720.7819 294.8349  1015.617
3. 2019-11 741.2318 312.8748 1054.107
4. 2019-12 734.6458 314.0186 1048.664
5. 2020-01 754.9029 328.4743 1083.377
6. 2020-02 741.4250 330.2179 1071.643
7. 2020-03 809.6948 363.0484 1172.743
8. 2020-04 809.5476 354.3307 1163.878

我想使用一个堆叠的、填充的条形图显示喜欢转发的比率,每个月一列,最大y值为1,最小为0。我怀疑我必须以某种方式使用
ggplot
geom_bar
identity
。任何帮助都将不胜感激

我想你需要以下几点:

library(dplyr)
library(tidyr)

df %>%
  dplyr::select(-Total) %>%
  pivot_longer(-Month) %>%
  ggplot(aes(x = Month, y = value, fill = name)) +
  geom_bar(stat='identity', position = 'fill')