ggplot2 - My R code creates plots in interactive mode, but not as a script (on Windows) -
ggplot2 - My R code creates plots in interactive mode, but not as a script (on Windows) -
this question has reply here:
ggplot's qplot not execute on sourcing 1 replythis code runs fine in interactive mode , creates plots specified. however, plots produced when run script blank. there way code work both script , interactively? i'm using rstudio version 0.98.1091, running on 32-bit windows 7. works fine 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()
save plot variable, print it:
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") plt = qplot(genes,expression,data=genes,stat="identity",geom="bar",fill=factor(genes)) print(plt) dev.off() png("genes_without_legend.png") plt = ggplot(genes,aes(genes,expression)) + geom_bar(stat="identity",fill=seq_along(factor(genes$genes)),legend.position="none") print(plt) dev.off()
values "autoprint" in interactive mode. example, right after type genes
in interactive mode, dataframe printed screen. however, don't expect printed file without print
statement. similarly, lattice/trellis/grid graphics (including ggplots) need printed when not in interactive mode. explicitly printing plot work both interactive , "script" modes.
this such mutual error listed in r-faq 7.22.
r ggplot2
Comments
Post a Comment