lpsolveapi を使用した優れた線形計画法の例を見つけました。これは R ブロガーで言及されており、元の投稿へのリンクはここにあります。Rscript は、こちらの Github からダウンロードできます。
問題は、コードがバージョン 0.9.1 より前の ggplot2 のバージョンに基づいていたことです。そのため、この例を実行すると、エラー メッセージはError: Use 'theme' instead. (Defunct; last used in version 0.9.1)
.
CRAN での提案は次のとおりです。
Error : Mapping a variable to y and also using stat="bin".
With stat="bin", it will attempt to set the y value to the count of cases in each group.
This can result in unexpected behavior and will not be allowed in a future version of ggplot2.
If you want y to represent counts of cases, use stat="bin" and don't map a variable to y.
If you want y to represent values in the data, use stat="identity".
See ?geom_bar for examples. (Defunct; last used in version 0.9.2)
より新しいバージョンの ggplot2 に基づいてコードを再構築する必要があることは理解していますが、そこで行き詰まります。私は初心者なので、どこから始めればよいかわかりません。y に割り当てないようにしてstat='bin'
、 orを使用してみstat='identity'
ました。エラーのある混乱したコードを投稿する代わりに、古いファイルを更新できるかどうかを尋ねます。
コードの一部を次に示します。更新すると、他のセクションに複製できます。
results<-data.frame(cargo=rep(cargo$type, 3),
wagon=as.vector(sapply(train$wagon,
FUN=function(x) rep(x, NROW(cargo)))), solution=get.variables(lpmodel))
r1<-ggplot(results, aes(x=cargo, y=solution, fill=wagon)) +
geom_bar(color='black', position='dodge') +
geom_text(aes(label=solution), size=2.5, position=position_dodge(width=1), vjust=-.4) +
scale_fill_brewer(palette='Set1') +
facet_grid(.~wagon) +
opts(title='Planning result', legend.position='none') +
ylab('Solution (tonnes)')