Aesthetics must either be length one, or the same length as the dataProblems

后端 未结 5 571
[愿得一人]
[愿得一人] 2020-12-05 04:09

I would like to make a plot with X values as a subset of the measurement and Y-values as another subset of the measured data.

In the example as below, I have 4 produ

5条回答
  •  Happy的楠姐
    2020-12-05 04:56

    The problem is that skew isn't being subsetted in colour=factor(skew), so it's the wrong length. Since subset(skew, product == 'p1') is the same as subset(skew, product == 'p3'), in this case it doesn't matter which subset is used. So you can solve your problem with:

    p1 <- ggplot(df, aes(x=subset(price, product=='p1'),
                         y=subset(price, product=='p3'),
                         colour=factor(subset(skew, product == 'p1')))) +
                  geom_point(size=2, shape=19)
    

    Note that most R users would write this as the more concise:

    p1 <- ggplot(df, aes(x=price[product=='p1'],
                         y=price[product=='p3'],
                         colour=factor(skew[product == 'p1']))) +
                  geom_point(size=2, shape=19)
    

提交回复
热议问题