R 使用ggplot2创建散点图,其中许多回归线基于所有点和分组变量以及按分组变量的点

R 使用ggplot2创建散点图,其中许多回归线基于所有点和分组变量以及按分组变量的点,r,ggplot2,plot,graph,R,Ggplot2,Plot,Graph,我感兴趣的是在r中使用ggplot2创建散点图,其中1条回归线使用所有点创建该线,该图本身具有基于2级分组变量的不同点,并且存在与分组变量相关联的2条回归线 我想结合这张图中的1条总体回归线: 使用此图中的2条分组变量特定回归线: 这可能吗?如果是,怎么做 提前谢谢 #为散点图创建数据 ##感兴趣的数据集 虹膜 ##给艾里斯 colnames(iris) ###仅在iris$Species==setosa或versicolor的情况下创建数据集 ####iris$物种的唯一值 独特(鸢尾属

我感兴趣的是在r中使用ggplot2创建散点图,其中1条回归线使用所有点创建该线,该图本身具有基于2级分组变量的不同点,并且存在与分组变量相关联的2条回归线

我想结合这张图中的1条总体回归线:

使用此图中的2条分组变量特定回归线:

这可能吗?如果是,怎么做

提前谢谢


#为散点图创建数据
##感兴趣的数据集
虹膜
##给艾里斯
colnames(iris)
###仅在iris$Species==setosa或versicolor的情况下创建数据集
####iris$物种的唯一值
独特(鸢尾属$种)
####加载tidyverse包
图书馆(tidyverse)
#####仅在iris$Species==setosa或versicolor的情况下过滤数据集
iris_uuusetosa_或_versicolor%过滤器(iris$物种!=“virginica”)
#####将iris_uusetosa_或花色转换为数据帧

iris_uuusetosa_或_versicolor这就是你想要做的吗

ggplot(iris__setosa_or_versicolor, aes(x=Sepal.Length, y=Sepal.Width)) + 
    geom_point(aes(col=Species)) + 
    geom_smooth(method=lm, se=FALSE, color="green") + 
    geom_smooth(aes(col = Species), method=lm, se=FALSE, fullrange=TRUE) +
    labs(title="Scatter plot of Sepal.Length X Sepal.Width with dots as Species where\n Species is setosa or versicolor but not differentiated by species", x="Sepal.Length", y = "Sepal.Width") + 
  scale_colour_manual(values = c("#ff0000","#0000ff"))

ggplot(iris__setosa_or_versicolor, aes(x=Sepal.Length, y=Sepal.Width)) + 
    geom_point(aes(col=Species)) + 
    geom_smooth(method=lm, se=FALSE, color="green") + 
    geom_smooth(aes(col = Species), method=lm, se=FALSE, fullrange=TRUE) +
    labs(title="Scatter plot of Sepal.Length X Sepal.Width with dots as Species where\n Species is setosa or versicolor but not differentiated by species", x="Sepal.Length", y = "Sepal.Width") + 
  scale_colour_manual(values = c("#ff0000","#0000ff"))