geom_bar に position="fill" を使用しようとすると、エラーが発生します。ここにMWEがあります:
temp = data.frame( X=rep(1:10,10), weight=runif(100), fill=rbinom(100,size=3,p=.5) )
temp$weight[temp$fill==3] = 0
ggplot( temp, aes(x=X, weight=weight, fill=as.factor(fill)) ) +
geom_bar(bin_width=1)
ggplot( temp, aes(x=X, weight=weight, fill=as.factor(fill)) ) +
geom_bar(bin_width=1,position="fill")
最初の ggplot 呼び出しは正常に機能し、各バーがレベル 0、1、および 2 に対応する 3 色で構成されるバー プロットを生成します。凡例は最終レベル (3) を示していますが、重みは常に 0 であるため、そうではありません。プロットに表示されます。
ただし、2 回目の ggplot 呼び出しはエラーを返します。以前と同じプロットを返すことを期待していましたが、各バーの高さを 1 に拡大するだけです。