title: Improving graph quality while exporting in r
body: <p>I have written following code for comparing between to different variables over a period. The code works fine but only problem is when i output the file as &quot;jpeg&quot; the lines are not smooth and my arrow is not as smooth as i like it to be in other words the graph feels very low quality. But when i output it as &quot;pdf&quot; i get smooth lines and graph is of higher quality. But pdf files are high in file size and i need to insert these graphs in word file. I find it relatively easy to append jpeg into the word file. So is it possible to improve image quality while being in jpeg format. I tried using <code>res</code> argument in <code>jpeg()</code> but it doesnot output the graph as it is displayed in the rstudio.</p>
  <p>I will appreciate the help. Thanks!</p>
  <p>code:</p>
  <pre><code>library(shape)
  library(Hmisc)
  ### samples ######
  xaxs = seq(1,30,length=30)
  precip = sample(200:800, 30)
  ero = sample(0:10, 30, replace = T)
  #########
  
  svpth = getwd()
  nm = &quot;try.jpeg&quot;
  jpeg(paste0(svpth,&quot;/&quot;,nm), width=950 , height =760, quality = 200, pointsize =15)
  par(mar= c(5,4,2,4), oma=c(1,1,1,1))
  plot(xaxs,precip, type = &quot;p&quot;, pch=15, col=&quot;green&quot;, ylim = c(200,1000),
       xlab = &quot;Year&quot; , ylab = &quot;&quot;, cex.main=1.5, cex.axis=1.5, cex.lab=1.5)
  lines(xaxs, precip,lty =1, col=&quot;green&quot;)
  # xtick&lt;-seq(0,30, by=1)
  # axis(side = 1, at=xtick, labels = FALSE )
  minor.tick(nx=5, ny=2, tick.ratio=0.5, x.args = list(), y.args = list())
  mtext(&quot;Depth (mm)&quot;, side = 2, line = 2.7, cex = 1.5)
  par(new=T)
  plot(xaxs, (ero * 10), ylim = c(0,max(pretty(range((ero * 10))))+20), type = &quot;p&quot;, pch=20, cex=1.5, col=&quot;red&quot;, axes = F, xlab = &quot;&quot;, ylab = &quot;&quot;)
  lines(xaxs, (ero * 10),lty =2, col=&quot;red&quot;)
  axis(side = 4, at=pretty(range((ero * 10))), cex.axis = 1.5)
  # mtext(&quot;Erosion (t/ha/yr)&quot;, side = 4, line = 2.2, cex = 1.5)
  mtext(expression(paste(&quot;Erosion (t &quot;, ha^-1, yr^-1, &quot;)&quot;)), side = 4, line = 2.7, cex = 1.5)
  legend(&quot;topleft&quot;, legend = c(&quot;Precipitation&quot;,&quot;Erosion&quot;), lty = c(1,2), pch = c(15,20), col = c(&quot;green&quot;,&quot;red&quot;), cex = 1.6, bty = &quot;n&quot;)
  ####arrow
  Arrows(7, 85, 11, 90,lwd= 1.1)
  Arrows(26, 85, 21, 90, lwd= 1.1)
  txt = &quot;High erosion rates in \nwheat-planting years&quot;
  xt = 16
  yt = 85
  text(xt, yt, labels = txt, family=&quot;serif&quot;, cex = 1.23)
  sw = strwidth(txt)+1.4
  sh = strheight(txt) +6
  frsz = 0.38
  rect(xt - sw/2 - frsz, yt - sh/2 - frsz, xt + sw/2 + frsz, yt + sh/2 + frsz-1)
  # legend(15,80, legend = c(&quot;High erosion rates in \nwheat-planting years\n&quot;),
         # xjust = 0.5, yjust = 0.5)
  dev.off()
  </code></pre>