散点图中有多条平滑线条

时间:2015-01-11 17:16:59

标签: r graph bigdata scatter-plot

我在R上有以下内容,用于创建教育成本与教育水平的散点图:

scatterplot(Cost~Education.Level., reg.line=FALSE, smooth=TRUE, spread=FALSE, 
+   boxplots=FALSE, span=0.5, xlab="Education Level", ylab="Cost", data=Dataset)

分散图也给了我一条平滑的线。

这是从一个大型数据集开始工作的,该数据集还有许多其他变量,例如City等。现在,我如何将平滑曲线分成几个为City编号的小曲线。有3个不同的城市,所以我希望R给出一个散点图,其上有3条不同的平滑线。

1 个答案:

答案 0 :(得分:2)

您可以使用groups=参数。以下是使用内置数据的一个小例子:mtcars:

car::scatterplot(mpg~carb, reg.line=FALSE, smooth=TRUE, spread=FALSE, boxplots=FALSE, 
span=0.5, xlab="Education Level", ylab="Cost", groups=mtcars$am, data=mtcars)

enter image description here

相关问题