title: Plotting and saving R graph
body: <p>I have a bash script that tracks memory usage over time as a command is run. It spawns the desired command and then writes a log with column1 = "memory in use by program (gigs)" and column 2 is the time elapsed so far in seconds. e.g.</p>
  
  <pre><code>31.282 1470
  31.565 1480
  31.848 1490
  31.989 1500
  32.273 1510
  32.414 1520
  32.697 1530
  32.980 1540
  33.122 1550
  33.405 1560
  6.511 1570
  6.935 1580
  7.502 1590
  7.926 1600
  8.351 1610
  8.775 1620
  9.059 1630
  9.483 1640
  9.908 1650
  10.333 1660
  </code></pre>
  
  <p>What I want to do is wait until the process is complete and then use R to plot a graph of memory usage over time and save it in the current directory. I was playing around with R and I know exactly what commands I need to use:</p>
  
  <pre><code>&gt; heisenberg &lt;- read.csv(file="4644.log",head=FALSE,sep=" ")
  &gt; plot(heisenberg$V2,heisenberg$V1,type="o",col="red",main="Memory Usage Over Time",xlab="Time (seconds)",ylab="Memory (gigabytes)")
  &gt; text(max(heisenberg$V2),max(heisenberg$V1),max(heisenberg$V1)) #Displays max value
  </code></pre>
  
  <p>But the part I am stuck on is saving the graph as a jpg or png. Or how I could execute this command within my bash script. Would I absolutely need to have another script written in R language and run it? Would this be possible to do all in one?</p>
  
  <hr>
  
  <p><H1>Edit</H1>
  Here is the code for my script.r</p>
  
  <pre><code>png("mem_usage_2965.png",height=800,width=800)
  heisenberg &lt;- read.csv(file="2965.log",head=FALSE,sep=" ")
  plot(heisenberg$V2,heisenberg$V1,type="o",col="red",main="oases_k85",xlab="Time (seconds)",ylab="Memory (gigabytes)")
  text(max(heisenberg),max(heisenberg),max(heisenberg))
  dev.off()
  </code></pre>
  
  <p>Can anyone help as to why the text doesn't print the maximum value in the outputted png? I am calling it in a bash script like <code>R CMD BATCH script.r script.out</code></p>