Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>The problem</h2> <p>This does appear to be a bug, but it's a problem with <code>pdf()</code> and not with <code>Sweave()</code> itself. </p> <p>To see what I mean, try this call to <code>pdf()</code>. It produces the same defective plot displayed above:</p> <pre><code>pdf("pdfPlot.pdf") plot(0.5, 0.5, xlim = c(0,1), ylim = c(0,1)) legend("bottomright", c("data", "summary", "curve", "conf. region"), pch = c(2,1,NA,NA), lwd = c(NA,NA, 2,1)) dev.off() </code></pre> <p>By contrast, <code>cairo_pdf()</code> produces a plot that looks just fine:</p> <pre><code>cairo_pdf("cairo_pdfPlot.pdf") plot(0.5, 0.5, xlim = c(0,1), ylim = c(0,1)) legend("bottomright", c("data", "summary", "curve", "conf. region"), pch = c(2,1,NA,NA), lwd = c(NA,NA, 2,1)) dev.off() </code></pre> <h2>Solution 1: Use knitr.</h2> <p>If you are willing to make the switch to <code>knitr</code>, fixing this is easy. Just add <code>dev="cairo_pdf"</code> to your code chunk header (and, if you like, drop the <code>fig=TRUE</code>), like this:</p> <pre><code>&lt;&lt;dev="cairo_pdf"&gt;&gt;= ... ... @ </code></pre> <p>Processing the code is then as simple as doing <code>library(knitr); knit("myScript.Rnw")</code> in place of your current call to <code>Sweave("myScript.Rnw")</code></p> <h2>Solution 2: Construct your own call to \includegraphics{}.</h2> <p>If you must stick with <code>Sweave()</code>, doing something like this will get you around the problem:</p> <pre><code>&lt;&lt;results=tex, term=FALSE, echo=FALSE&gt;&gt;= cairo_pdf("myPlot.pdf", width=5) plot(0.5, 0.5, xlim = c(0,1), ylim = c(0,1)) legend("bottomright", c("data", "summary", "curve", "conf. region"), pch = c(2,1,NA,NA), lwd = c(NA,NA, 2,1)) dev.off() cat("\\includegraphics{myPlot.pdf}\n\n") @ </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload