Possible Duplicate:
Plotting and saving PDFs in a loop
Newbie’s issues.
My tab separated input data looks like that:
x y
1 50
2 25
3 60
4 25
5 90
6 100
Here is my code file “code.R”:
data <- read.table("input",header=T,sep="\t")
pdf("output.pdf")
ggplot (data,aes(x=x,y=y) + geom_bar(stat="identity")
dev.off()
I run the code with the command below and don’t get any error message in return:
source("code.R")
The code generates the “output.pdf” file but it is blank (error when I want to open it).
When I enter manually in my R terminal the 1st then the 2nd line of the above code, the graph looks correct in the graphic device.
When I write the lines below in a file and run the file, nothing happen (no errors, no graphic device window)
data <- read.table("input",header=T,sep="\t")
ggplot (data,aes(x=x,y=y)) + geom_bar(stat="identity")
The line endings of both input and code files are in windows format.
I also tried data <- as.data.frame(read.table(...)) but it changes nothing.
I really don’t see what’s wrong in my code…
Any advice and explanations would be great !
Thanks !
You’re missing a close parentheses for your ggplot call.
This line:
Should be:
Or you can try ggsave() instead of pdf() dev.off() like this:
Don’t mix the two methods.