【问题标题】:Multiple smooth lines in scatterplot散点图中的多条平滑线
【发布时间】:2015-01-11 17:16:59
【问题描述】:

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

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

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

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

【问题讨论】:

  • 你能提供一些数据吗?
  • 我真的没有,我只是在玩。这是基本的 3 个离散变量:教育水平、教育成本、城市
  • 如果它不必是 scatterplot 函数,我会建议 ggplot2 这样做的方式,如下所述:docs.ggplot2.org/current/aes_group_order.html
  • 如何开始使用 ggplot?
  • 这个包网上有很多介绍

标签: r graph bigdata scatter-plot


【解决方案1】:

您可以使用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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 2021-09-30
    • 1970-01-01
    • 2016-04-17
    • 2020-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多