title: R using ggplot2: "Error in value == "primary" : comparison is not allowed for expressions"
body: <p>I am attempting to change the labels in the handy facet plot available in R with ggplot using a function that I created, facet_labeller:</p>
  
  <pre><code>#This function will map a new name to the category labels
  facet_labeller &lt;- function(var, value){
    value &lt;- as.character(value)
  
    # Creates labels with superscript for 1st and 2nd solvation shells
    label_primary &lt;- expression(1^{st} ~ Shell)
    label_secondary &lt;- expression(2^{nd} ~ Shell)
  
    if (var=="solvent") {
      value[value=="meoh"] &lt;- "Methanol"
      value[value=="water"]   &lt;- "Water"
    }
    if (var=="shell") {
      value[value=="secondary"] &lt;- label_secondary
      value[value=="primary"] &lt;- label_primary
    }
    if (var=="ion") {
      value[value=="Cl"] &lt;- "Cl"
      value[value=="Na"] &lt;- "Na"
    }
    return(value)
  }
  </code></pre>
  
  <p>When the function is called by facet_grid:</p>
  
  <pre><code>facet_grid(shell + ion ~ solvent, scales="free_y", labeller=facet_labeller)
  </code></pre>
  
  <p>I get the error "Error in value == "primary" : comparison is not allowed for expressions"</p>
  
  <p>I do not understand at all why this is occurring. Changing the line cited by the error will fix things and allow the plot to be created; for example, I can simply comment that line out, or I can put a string instead of the 'label_primary' variable. I need to use the expression, however, because of the superscripts.</p>
  
  <p>Why is this happening? Why doesn't it happen with just one check in that if block? How can I get this to work? Any help would be greatly appreciated - I am at a total loss.</p>