带有水平线的散点图表示 R 和 ggplot 的平均值
Scatter plot with horizontal lines representing averages with R and ggplot
下面的代码为每个组生成一个带有回归线的散点图。除了倾斜的回归线之外,是否可以绘制代表每组 y 值平均值的水平线?我尝试将公式参数修改为 "y ~ 0 *x",但想不出其他明显可以使用的东西。
谢谢
ggplot(data = iris, aes(y = Sepal.Length, x = Sepal.Width, colour = Species)) + geom_point() +
geom_smooth(method = 'lm', formula = y ~ x , se = F)
我们可以指定公式为y ~ 1
。
library(ggplot2)
ggplot(data = iris, aes(y = Sepal.Length, x = Sepal.Width, colour = Species)) +
geom_point() +
geom_smooth(method = "lm", formula = y ~ 1)
下面的代码为每个组生成一个带有回归线的散点图。除了倾斜的回归线之外,是否可以绘制代表每组 y 值平均值的水平线?我尝试将公式参数修改为 "y ~ 0 *x",但想不出其他明显可以使用的东西。
谢谢
ggplot(data = iris, aes(y = Sepal.Length, x = Sepal.Width, colour = Species)) + geom_point() +
geom_smooth(method = 'lm', formula = y ~ x , se = F)
我们可以指定公式为y ~ 1
。
library(ggplot2)
ggplot(data = iris, aes(y = Sepal.Length, x = Sepal.Width, colour = Species)) +
geom_point() +
geom_smooth(method = "lm", formula = y ~ 1)