Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Q1: Does anybody have any explanations for this behavior?</p> </blockquote> <p>These are three reasons behind why tikzDevice gives an error when trying to construct your plot:</p> <ul> <li><p>When you add an aesthetic mapping that creates a legend, such as <code>aes(colour=que_id)</code>, ggplot2 will use the variable name as the title of the legend---in this case, que_id.</p></li> <li><p>The tikzDevice passes all strings, such as legend titles, to LaTeX for typesetting.</p></li> <li><p>In LaTeX the underscore character, <code>_</code>, is used to denote a subscript. If an underscore is used outside of math mode, it causes an error.</p></li> </ul> <p>When the tikzDevice tries to calculate the height and width of the legend title, "que_id", it passes the string to LaTeX for typesetting and expects LaTeX to return the width and height of the string. LaTeX suffers an error because there is an unescaped underscore used in the string outside of mathmode. The tikzDevice receives a <code>NULL</code> for the string width instead of a number which causes an <code>if (width &gt; 0)</code> check to fail.</p> <p><strong>Ways to avoid the problem</strong></p> <ol> <li><p>Specify a legend title to use by adding a color scale:</p> <pre><code>p1 &lt;- ggplot(plot_info, aes(elevation, area)) p1 &lt;- p1 + geom_point(aes(colour=que_id)) # Add a name that is easier for humans to read than the variable name p1 &lt;- p1 + scale_colour_brewer(name="Que ID") # Or, replace the underscore with the appropriate LaTeX escape sequence p1 &lt;- p1 + scale_colour_brewer(name="que\\textunderscore id") </code></pre></li> <li><p>Use the string sanitization feature introduced in tikzDevice 0.5.0 (but was broken until 0.5.2). Currently, string sanitization will only escape the following characters: <code>%</code>, <code>$</code>, <code>{</code>, <code>}</code>, and <code>^</code> by default. However, you can specify additional substitution pairs via the <code>tikzSanitizeCharacters</code> and <code>tikzReplacementCharacters</code> options:</p> <pre><code># Add underscores to the sanitization list options(tikzSanitizeCharacters = c('%','$','}','{','^', '_')) options(tikzReplacementCharacters = c('\\%','\\$','\\}','\\{', '\\^{}', '\\textunderscore')) # Turn on string sanitization when starting the plotting device tikz('myPlot.tex', standAlone = TRUE, sanitize = TRUE) print(p1) dev.off() </code></pre></li> </ol> <p>We will be publishing version 0.5.3 of the tikzDevice in the next couple of weeks in order to address some annoying warning messages that now show up due to changes in the way R handles <code>system()</code>. I will add the following changes to this next version:</p> <ul> <li><p>Better warning message when <code>width</code> is <code>NULL</code> indicating that there is probably something wrong with plot text.</p></li> <li><p>Add underscores and a few other characters to the default set of characters that the string sanitizer looks for.</p></li> </ul> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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