I found a great linear programming example using lpsolveapi. It was mentioned on R bloggers, and the link to the original post can be found here. The Rscript can be downloaded from Github here.
The problem is that the code was based on a version of ggplot2 pre version 0.9.1. So when running the example, the error message is Error: Use 'theme' instead. (Defunct; last used in version 0.9.1)
.
On CRAN, the suggestion is:
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)
I understand that the code has to reformulated based on the more recent version of ggplot2, but that's where I get stuck. Being the beginner that I am, I don't know where to start. I tried not assigning to y and I tried using stat='bin'
or stat='identity'
. Instead of me posting my messing code with errors, I will rather ask if the outdated file could be updated.
Here is a section of the code, that if updated, I could replicate to the other sections:
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)')