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 generates a scatterplot using the ggplot2 library. The x-axis displays 'Awareness' while the y-axis represents 'Group'. Points are colored based on their 'Group' using the scale_color_manual function. Two regression lines are added using the geom_smooth function, employing 'lm' for linear regression. The se argument is set to FALSE to omit confidence intervals. The title, x-axis label, y-axis label, and theme are customized using the labs and theme_bw functions.

This approach effectively visualizes the relationship between 'Awareness' and 'Group' without requiring the qqline function, providing a clear representation of the data and trends within each group.


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

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