R 如何在ggplot中的一个条形图中使用两个不同的变量对列进行条形图绘制

R 如何在ggplot中的一个条形图中使用两个不同的变量对列进行条形图绘制,r,ggplot2,geom-bar,geom-col,R,Ggplot2,Geom Bar,Geom Col,我有这个df:estudios_intubacion estudio_completo numero <chr> <int> 1 COMPLETO 2838 2 INCOMPLETO 147 estudio\u completo numero 1至2838 2不完整147 我试着用两个变量,x轴的estudio_completo(completo和INCOMPLETO)和y轴的'n'来绘制一个条/列

我有这个df:estudios_intubacion

  estudio_completo numero
  <chr>             <int>
1 COMPLETO           2838
2 INCOMPLETO          147
estudio\u completo numero
1至2838
2不完整147
我试着用两个变量,x轴的estudio_completo(completo和INCOMPLETO)和y轴的'n'来绘制一个条/列。我试过用很多方法来定位“堆叠”和“填充”,但我总是得到两个没有比例的独立条

grafico_intubacion <- ggplot(estudios_intubacion, 
                         aes (x = estudio_completo, fill = estudio_completo))+
                          geom_bar(position = "stack") +
                        labs(title = "Tasa de intubación cecal",
                               x = "Estudio",
                               y = "Cantidad de estudios",
                             fill = "Estudio" ) +
                        scale_fill_manual(values = c("#C7CEEA", "#FF9AA2"))

grafico\u intubacion试试这个

x <- rep("Estudio",2)
y <- c(2838,147)
name <- c("COMPLETO","INCOMPLETO")
df <- data.frame(x,y,name)

grafico_intubacion <- ggplot(df, aes(x = x, y=y, fill = name)) +
  geom_bar(stat = "identity") + 
  labs(title = "Tasa de intubación cecal",
       x = "Estudio",
       y = "Cantidad de estudios",
       fill = "Estudio" ) +
  scale_fill_manual(values = c("#C7CEEA", "#FF9AA2"))

grafico_intubacion

x谢谢!这就是我要找的!