title: R plotly - Plotting grouped lines
body: <p>I am migrating over from ggplot2 to plotly, in order to take advantage of the interactive features they offer.</p>
  
  <p>I do realize that the plotly library has a ggplotly function I can use to encapsulate native ggplot commands, but I wanted to learn how to plot similar graphs using native plotly commands.</p>
  
  <p>My problem is that I can't seem to make plotly draw grouped lines the way ggplot2 does.</p>
  
  <h2>Base Data, using the default mpg data set from ggplot2</h2>
  
  <pre><code>mpg %&gt;%
    group_by(manufacturer, class) %&gt;%
    summarise(models=n())
  
  |manufacturer |class      | models|
  |:------------|:----------|------:|
  |audi         |compact    |     15|
  |audi         |midsize    |      3|
  |chevrolet    |2seater    |      5|
  |chevrolet    |midsize    |      5|
  |chevrolet    |suv        |      9|
  |dodge        |minivan    |     11|
  |dodge        |pickup     |     19|
  |dodge        |suv        |      7|
  |ford         |pickup     |      7|
  |ford         |subcompact |      9|
  |ford         |suv        |      9|
  |honda        |subcompact |      9|
  |hyundai      |midsize    |      7|
  |hyundai      |subcompact |      7|
  |jeep         |suv        |      8|
  |land rover   |suv        |      4|
  |lincoln      |suv        |      3|
  |mercury      |suv        |      4|
  |nissan       |compact    |      2|
  |nissan       |midsize    |      7|
  |nissan       |suv        |      4|
  |pontiac      |midsize    |      5|
  |subaru       |compact    |      4|
  |subaru       |subcompact |      4|
  |subaru       |suv        |      6|
  |toyota       |compact    |     12|
  |toyota       |midsize    |      7|
  |toyota       |pickup     |      7|
  |toyota       |suv        |      8|
  |volkswagen   |compact    |     14|
  |volkswagen   |midsize    |      7|
  |volkswagen   |subcompact |      6|
  </code></pre>
  
  <h2>Example 1: This works</h2>
  
  <pre><code>mpg %&gt;%
    group_by(manufacturer, class) %&gt;%
    summarise(models=n()) %&gt;%
    plot_ly(x=~class, y=~models, type="scatter", mode="lines+marker", color=~manufacturer)
  </code></pre>
  
  <h2>Example 2: But this returns only a blank plot</h2>
  
  <p>Difference with Example 1 is that I'm trying to group by class instead of manufacturer.</p>
  
  <pre><code>mpg %&gt;%
    group_by(manufacturer, class) %&gt;%
    summarise(models=n()) %&gt;%
    plot_ly(x=~manufacturer, y=~models, type="scatter", mode="lines+marker", color=~class)
  </code></pre>
  
  <h2>Example 3: This is the ggplot2 version of how I would like it plotted</h2>
  
  <pre><code>mpg %&gt;%
    group_by(manufacturer, class) %&gt;%
    summarise(models=n()) %&gt;%
    ggplot(aes(x=manufacturer, y=models, group=class, color=class)) +
      geom_line() +
      theme_minimal()
  </code></pre>
  
  <p>How could I make Example 2 look like Example 3?</p>