title: R: elements missing when saving to PDF
body: <p>R version 3.2.2 | R - Studio Version 0.99.484 | Windows 7</p>
  
  <p>I am trying to plot and save to PDFs. When plotting to the plots-window in R-studio my plot appears nicely and I can manually save it from there. The saved PDF then looks as expected.</p>
  
  <p>However, when trying to save the plot in my code, the legend and some text-elements are missing.</p>
  
  <pre><code>pdf(file=paste(filetitle, ".pdf",sep=""),paper="A4")
  plotting_function(various parameters)
  
  for (n in 1:number){
    x=sin(rad((-n+1)*deg))
    y=cos(rad((-n+1)*deg))
    km1_val=as.numeric(maxmin[4,n])
    km2_val=as.numeric(maxmin[3,n])
    if (km2_val&gt;km1_val){
      km1_displace=0.8
      km2_displace=1.15
      }
    else {
    km2_displace=0.8
    km1_displace=1.15
      }
   text(x*km1_displace*km1_val/10, y*km1_displace*km1_val/10,round(maxmin[4,n],1),font=2,cex = .8,col=line_col_1)
   text(x*km2_displace*km2_val/10, y*km2_displace*km2_val/10, round(maxmin[3,n],1),font=2,cex = .8,col=line_col_2)
    }
  
  legend(.55,-1.3,bty = "n",legend=c(colnames(q_data)[2],colnames(q_data)7]),cex=0.8,pch=c(16,16),col=c(line_col_2,line_col_1),lty=c(1,1))
  text(0,1.5,title,font=2,cex=1.5)
  text(-0.7,-1.4,"My_text",font=1,cex=.8)
  dev.off()
  </code></pre>
  
  <p>The result of the plotting-function and the text-elements in the loop are included in the saved PDF, but the legend and the two text-elements below it are not included.</p>
  
  <p>I have tried to use print() without success. </p>
  
  <p>Any obvious mistakes?</p>