I'm trying to plot filled rectangles using the following code -
tplot.old <- ggplot() +
geom_rect(data=t.df,mapping=aes(xmin=xa, xmax=xb, ymin=ya, ymax=yb, fill=Train)) +
ylab("Cars per week") + xlab("Miles") + ggtitle(old.title) +
theme(axis.text.x = element_text(angle=45,size=5,hjust=1), axis.text=element_text(size=5), axis.text.y = element_text(size=5), title=element_text(size=5), legend.text=element_text(size=5)) +
scale_fill_manual(values=color_values) +
scale_x_continuous(breaks=plot.stns$Avg_Miles,labels=plot.stns[,"City_Name"]) +
coord_cartesian(xlim=c(0,1700),ylim=c(0,500))
t.df looks like this:
Train xa xb ya yb col
a MHKNP 407 1594 0 22.806452 red
b MPDNP 407 1594 0 9.258065 darkgreen
cd MHKRO 407 1594 0 5.258065 orange
and plot.stns:
Avg_Miles City_Name
1 0 EUGENE
4 15 BLAKESLEEJCT
12 64 LONGVIEWJCT
25 118 ALBINA
45 306 HINKLE
This seems to work when I plot this interactively on the console, but inside a for loop gives this error -
Error: Discrete value supplied to continuous scale
color_values :
MHKNP MHKNPB MHKPC MHKRO MPCGR MPSHK
"red" "green" "blue" "maroon" "orange" "black"
QCONP QPCNPP MPDNP
"magenta" "skyblue" "darkgreen"
This is somehow related to scale_x_continuous (it does not give the error when I remove it), but I can't figure out what is wrong here. Any ideas?

+s at the end of the layers in order to add more - rawr