要求:至少3列数据,其中一列是用来分类的:
> head(data)
xname yname type
1 0 .. type1
2 1 .. type1
3 2 .. type2
4 3 .. type2
5 4 .. type1
6 5 .. type2
p <- ggplot(data, aes(x = xname, y = yname, color = type) ) +
geom_point() +
geom_smooth(method = "lm", se = FALSE)
> p
这里主要是两点:
color = type
: 使用颜色进行了分类geom_smooth(method = "lm", se = FALSE)
:添加回归线试过指定group=type
,或者指定geom_point()
中的shape=type
不起作用,会报错。
有更好的办法欢迎补充。