在R中,如何绘制表示长数据比例的条形图

在R中,如何绘制表示长数据比例的条形图,r,plot,graph,R,Plot,Graph,df2 我运行一个函数来查找零食的顶级配料 Meal Contents apple banana beef berry blackberry cantaloupe chicken mashpotatoes redberries rice strawberry stringbeans 1 Snack_1 redberries,strawberry,blackberry 0 0 0 0

df2

我运行一个函数来查找零食的顶级配料

   Meal                           Contents apple banana beef berry blackberry    cantaloupe chicken mashpotatoes redberries rice strawberry stringbeans

1 Snack_1   redberries,strawberry,blackberry     0      0    0     0              1          0       0            0          1    0          1           0
2 Snack_2           banana,apple,strawberry,     1      1    0     0          0          0       0            0          0    0          1           0
3 Snack_3                       rice,chicken     0      0    0     0          0          0       1            0          0    1          0           0
4 Snack_4      beef,stringbeans,mashpotatoes     0      0    1     0          0          0       0            1          0    0          0           1
5 Snack_5 banana,strawberry,berry,cantaloupe     0      1    0     1          0          1       0
当我尝试绘制此值时,它会在绘图上生成一个点。 但我想让它显示条形图来显示每种成分是如何相互公平的。在R

中使用基本R&ggplot2时是否可能:

     Berry           10
     Strawberry     200
     Cantalopue      30

带有基本R&ggplot2:

     Berry           10
     Strawberry     200
     Cantalopue      30

您可以使用
stat=“identity”
ggplot2
包(
library(ggplot2)
)中尝试
geom\u bar
。假设上面生成的数据帧被称为
df
,其中包含
成分
列和
数量
,我们可以进行
ggplot(df,aes(x=因子(成分),y=数量))+geom_-bar(stat=“identity”)
。参考:您可以使用
stat=“identity”
ggplot2
包(
library(ggplot2)
)中尝试
geom\u bar
。假设上面生成的数据帧被称为
df
,其中包含
成分
列和
数量
,我们可以进行
ggplot(df,aes(x=因子(成分),y=数量))+geom_-bar(stat=“identity”)
。参考:
df
     Fruit Count
1      Berry    10
2 Strawberry   200
3 Cantalopue    30

barplot(df$Count, names.arg=df$Fruit, ylab='Count')

library(ggplot2)
ggplot(df, aes(Fruit, Count)) + geom_bar(stat='identity')