以下の時系列の例でデータが欠落した場合に、geom_bar()
の一定の幅を設定する方法はありますか?私は運がないaes()
にwidth
を設定しようとしました。コード例の下のプロットで5月11日から6月11日までの幅を比較してください。データがない場合のgeom_barの一貫性のある幅
colours <- c("#FF0000", "#33CC33", "#CCCCCC", "#FFA500", "#000000")
iris$Month <- rep(seq(from=as.Date("2011-01-01"), to=as.Date("2011-10-01"), by="month"), 15)
colours <- c("#FF0000", "#33CC33", "#CCCCCC", "#FFA500", "#000000")
iris$Month <- rep(seq(from=as.Date("2011-01-01"), to=as.Date("2011-10-01"), by="month"), 15)
d<-aggregate(iris$Sepal.Length, by=list(iris$Month, iris$Species), sum)
d$quota<-seq(from=2000, to=60000, by=2000)
colnames(d) <- c("Month", "Species", "Sepal.Width", "Quota")
d$Sepal.Width<-d$Sepal.Width * 1000
g1 <- ggplot(data=d, aes(x=Month, y=Quota, color="Quota")) + geom_line(size=1)
g1 + geom_bar(data=d[c(-1:-5),], aes(x=Month, y=Sepal.Width, width=10, group=Species, fill=Species), stat="identity", position="dodge") + scale_fill_manual(values=colours)
は、同様の問題は[こちら](ありhttps://github.com/hadley/ggplot2/issues/235)しかし、これはwidthパラメータを扱うことができない 'stats'しか扱っていません。 'position = 'dodge''は同じ失敗をしているようです。 'ggplot'の知識がもう少しある人は、体重を増やしたいと思うかもしれませんが、これは潜在的なバグのようです。 – Justin
私もその問題に出会った。知っておいてよかった。今のところ、NAで値を入力することで、以下の回避策を使用します。 – tcash21
https://github.com/tidyverse/ggplot2/issues/1776への彼の返信で、ハドリーはこう述べています。あなたは代わりにファセットを試してみるといいかもしれません。_BTW、この問題はすでにSOに数回言及されています:[ここ](http://stackoverflow.com/q/12806260/3817004)と[here](http:// stackoverflow .com/q/15367762/3817004)、例えば – Uwe