在ggplot2

时间:2016-11-13 12:34:51

标签: ggplot2

我使用ggplot2绘制图表,基本目标是: 图形有两层,下层(散点图)将使用从公共数据库收集的数据,然后我将在我的研究的顶部添加数据。我还为我的数据添加了回归线。您可以从这张图片中简要了解我的内容: enter image description here 问题是,由于两个数据集的不同维度,回归线太长(全范围),这使得图片看起来很奇怪。我想为我的数据层定义x和y轴,但是,我无法达到此目的。

对于回归,我使用geom_abline来定义斜率,截距等,而不是使用geom_lm,我看到它可以使用参数fullrange = FALSE

1 个答案:

答案 0 :(得分:0)

stat_smoothmethod = "lm"se = FALSE一起使用(关闭置信区间阴影)。

ggplot(mpg, aes(displ, cty, color = as.factor(cyl))) + 
    geom_point() +
    stat_smooth(method = "lm", se = FALSE) +
    labs(color = "Cylinders",
         x = "Displacement in Liters",
         y = "Miles per Gallon")

1

相关问题