control color of multiple geom_line in ggplot2 in R

前端 未结 1 1668
闹比i
闹比i 2021-01-28 22:50

I want to plot 3 regression lines, one for each value of tau, and each one with its colour, as specified in the dataset. The internet says you provide the color variable at the

相关标签:
1条回答
  • ggplot 'maps' aesthetics to scales, meaning that it tries to fit a variable onto a scale. The default scale for categorical variables is scale_colour_discrete(), which matches a colour to every unique entry. Since ggplot doesn't know that the values in your col column are colour names, you have to let ggplot know that these colours are to be interpreted literally. You can do that with scale_colour_identity().

    ggplot(ddl, aes(x = predictor, y = value, color = col)) + 
      geom_line(aes(group = tau),size = 0.8) +
      scale_colour_identity()
    

    0 讨论(0)
提交回复
热议问题