title: Knitting R markdown (with plot() function) to PDF gives error
body: <p>While knitting an RMD to PDF, I get the following error:</p>
  <pre><code>Quitting from lines 47-76 (ABC.Rmd) 
  Error in (function (file = if (onefile) &quot;Rplots.pdf&quot; else &quot;Rplot%03d.pdf&quot;,  : 
    cannot open file '~/Read and visualize the &quot;governorate&quot; shapefile-1.pdf'
  </code></pre>
  <p>If I try to see it works for an HTML, then I get the following error:</p>
  <pre><code>Quitting from lines 47-76 (ABC.Rmd) 
  Error in png(..., res = dpi, units = &quot;in&quot;) : unable to start png() device
  Calls: &lt;Anonymous&gt; ... in_dir -&gt; plot2dev -&gt; do.call -&gt; &lt;Anonymous&gt; -&gt; png
  In addition: Warning messages:
  1: In png(..., res = dpi, units = &quot;in&quot;) :
    unable to open file '~/Read and visualize the &quot;governorate&quot; shapefile-1.png' for writing
  2: In png(..., res = dpi, units = &quot;in&quot;) : opening device failed
  </code></pre>
  <p>Now I don't know if it has to do with the plot function, as I never get this error with &quot;ggplot&quot;</p>
  <pre><code>```{r Read and visualize the &quot;governorate&quot; shapefile, echo = FALSE}
  # Import the Iraqi regions shapefile
  Iraq_Regions =  readOGR(dsn = &quot;~/governorates.shp&quot;)
  # Import the Baghdad neighborhood shapefile 
  Baghdad_Neigh = readOGR(dsn = &quot;~/baghdad_neighborhoods.shp&quot;)
  # Plot the Wiki Leaks data frame
  plot(x=Wiki_Leaks$Longitude, y=Wiki_Leaks$Latitude, pch=20, col='red', cex=0.4)
  plot(Iraq_Regions, border='blue', add=T)
  plot(Baghdad_Neigh, border='yellow', add=T)
  
  # Merge neighborhoods to make the Baghdad city outline
  Greater_Baghdad &lt;- gUnaryUnion(Baghdad_Neigh)
  
  # Plot the shapefiles 
  plot(x=Wiki_Leaks$Longitude, y=Wiki_Leaks$Latitude, pch=20, col='red', cex=0.4)
  plot(Iraq_Regions, border='blue', add=T)
  plot(Greater_Baghdad, border='yellow', add=T)
  
  # view the names of different regions and the numbers of records in each region
  #table(Wiki_Leaks$Region)
  
  # Retrieve all events near Baghdad
  Wiki_Leaks_MND_N_df = Wiki_Leaks[Wiki_Leaks$Region == &quot;MND-N&quot;, ]
  
  # Now make a basic plot
  plot(x = Wiki_Leaks_MND_N_df$Long, y = Wiki_Leaks_MND_N_df$Lat,
       pch = 20, col = 'red', cex = 0.4,
       ylab = &quot;Longitude&quot;, xlab = &quot;Latitude&quot;, 
       main = &quot;Death Events in Baghdad Neihborhood MND-N&quot;)
  
  ```
  </code></pre>