Note that there are some explanatory texts on larger screens.

plurals
  1. PODodge by another group with ggplot2
    primarykey
    data
    text
    <p>I am trying to plot a line over a bunch of points by certain groups. For example, I have:</p> <pre><code>x = rep(c('fruit', 'vegetable'), 15) z = c(rep(c(rep('fresh', 2), rep('ripe', 2), rep('rotten', 2)), 5) s = c(rep('pick1', 6), rep('pick2', 6), rep('pick3', 6), rep('pick4', 6), rep('pick5', 6)) y = runif(30, min=11, max=15) low = rep(c(0, 1), 15) y[low == 1] = y[low == 1] - 10 y[low == 0] = y[low == 0] - 5 groceries_df = data.frame(type=x, value=y, age=z, species=s) </code></pre> <p>where type is either "fruit" or "vegetable", age is either "fresh", "ripe", or "rotten", and species is a unique list of different picks from a store, so there are 2*3 = 6 values for each species. I am grouping these values on a discrete x-axis defined by their age, and they are grouped by their type (and thus dodged by their type).</p> <pre><code>dodge = position_dodge(width=0.9) p = ggplot(groceries_df, aes(factor(age), value, color=factor(type), shape=factor(type))) + geom_jitter(position=dodge) + geom_line(data=groceries_df[groceries_df$type == 'fruit',], aes(group=factor(species)), position=dodge) + geom_line(data=groceries_df[groceries_df$type == 'vegetable',], aes(group=factor(species)), position=dodge) </code></pre> <p>This code produces a plot extremely close to what I want, but I noticed that geom_line dodges by species, not by type. It seems as though I just need to redirect the dodge, even though I need the actual lines to be grouped by species (so I can see the transition of one species' value from one type to the next at all ages). Is there any way to redirect dodge?</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.
 

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