ggplot2: multiple colours in stat_summary

后端 未结 1 903
死守一世寂寞
死守一世寂寞 2021-01-14 07:06

I have a plot in which I am displaying individual values from multiple subjects, coloured by group. Added to that are means per group, calculated using stat_summary.

相关标签:
1条回答
  • 2021-01-14 07:44

    You need to create different values for the mapping to color:

    ggplot(data=iris, 
           aes(x=Sepal.Length, y=Sepal.Width, color=Species)) + 
      geom_line() + geom_point() + theme_bw() +
      stat_summary(fun.y=mean, geom="line", size=1.5,
                   linetype="dotted", aes(color=paste("mean", Species)))
    

    resulting plot

    You can then use scale_color_manual to get specific colors.

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