This code runs fine in interactive mode and creates the plots specified. However, the plots produced when run as a script are blank. Is there a way to code this that would work both as a script and interactively? I'm using RStudio version 0.98.1091, running on 32-bit Windows 7. This works fine as a script on Linux.
library(ggplot2)
genes <- data.frame(Genes=c("A","B","C","D","E"),
Expression=c(1,7.6,100,2,67)
)
png("genes_with_legend.png")
qplot(Genes,Expression,data=genes,stat="identity",geom="bar",fill=factor(Genes))
dev.off()
png("genes_without_legend.png")
ggplot(genes,aes(Genes,Expression)) + geom_bar(stat="identity",fill=seq_along(factor(genes$Genes)),legend.position="none")
dev.off()