我在食品数据框中有两个二进制值列,如下所示:
foods$veryHealthy:
"False" "False" "True" "True" "False" "False" "False" "True" "False" "False" "True" "False"
"True" "False" "False" "True" "False" "True" "False" "False" "True" "False" "False" "False" ...
foods$dairyFree:
"True" "True" "True" "True" "True" "True" "True" "True" "False" "True" "True" "False"
"True" "False" "False" "True" "True" "True" "True" "False" "True" "False" "True" "True" ...
I want to get some plot like:
对于 x 轴而不是四个类别,我想使用二进制值。
请注意条的粗细如何根据每个类中的实例数而变化。
我尝试了以下代码,但没有得到结果:
ggplot(foods, aes(x=veryHealthy, y=dairyFree, fill=dairyFree)) +
geom_col(position = "fill")
编辑:我必须使用 ggplot2 而不是任何内置或其他库。