R stat_smooth all points

匿名 (未验证) 提交于 2019-12-03 02:14:01

问题:

From Plot vectors of different length with ggplot2, I've got my plot with lines.

ggplot(plotData, aes(x, y, label=label, group=label)) + geom_line() + stat_smooth() 

But this smooths one line each. How do I smooth over all data points?

回答1:

ggplot(plotData, aes(x, y, label=label, group=label)) +      geom_line() +     geom_smooth(aes(group = 1)) 

should do it. The idea here is to provide a new group aesthetic so that the fitted smoother is based on all the data, not the group = label aesthetic.

Following the example from @Andrie's Answer the modification I propose would be:

ggplot(plotData, aes(x, y, label=label, group=label)) +      geom_text() +      geom_smooth(aes(group = 1)) 

which would produce:



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!