Assuming you have two variables, "Awareness" and "Group", where "Group" is a categorical variable with two levels (e.g. "Group 1" and "Group 2"), you can use the following code to create a scatterplot with two regression lines:

# Load ggplot2 library
library(ggplot2)

# Create sample data
Awareness <- c(2, 4, 6, 8, 10, 3, 5, 7, 9, 11)
Group <- c(rep("Group 1", 5), rep("Group 2", 5))
df <- data.frame(Awareness, Group)

# Create scatterplot with two regression lines
ggplot(df, aes(x = Awareness, y = Group, color = Group)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  scale_color_manual(values = c("red", "blue")) +
  labs(title = "Scatterplot of Awareness by Group",
       x = "Awareness",
       y = "Group") +
  theme_bw()

This code creates a scatterplot using the ggplot2 library, where the x-axis represents "Awareness" and the y-axis represents "Group". The points are colored by "Group" using the scale_color_manual function. Two regression lines are added using the geom_smooth function with the method argument set to "lm" for linear regression. The se argument is set to FALSE to remove the confidence intervals. The title, x-axis label, y-axis label, and theme are customized using the labs and theme_bw functions.

Note that the code does not include qqline as it is not necessary for creating a scatterplot with regression lines


原文地址: https://www.cveoy.top/t/topic/ddpd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录