Assuming you have a dataset with two columns, one for Awareness and one for another variable (e.g. Sales), you can use the following code to create a scatterplot with two regression lines:

# Load the ggplot2 library
library(ggplot2)

# Create a dataframe with two groups of Awareness
df <- data.frame(Awareness = c(1, 2, 3, 4, 5, 1, 2, 3, 4, 5),
                 Sales = c(10, 15, 20, 25, 30, 12, 18, 22, 28, 32))

# Create a scatterplot with two regression lines
ggplot(df, aes(x = Awareness, y = Sales)) +
  geom_point() +
  geom_smooth(method = 'lm', se = FALSE, aes(color = 'Group 1')) +
  geom_smooth(data = subset(df, Awareness > 3), method = 'lm', se = FALSE, aes(color = 'Group 2')) +
  scale_color_manual(values = c('Group 1' = 'blue', 'Group 2' = 'red')) +
  labs(title = 'Scatterplot of Awareness and Sales',
       x = 'Awareness', y = 'Sales')

In this example, we use the ggplot2 library to create a scatterplot with Awareness on the x-axis and Sales on the y-axis. We add two regression lines using the geom_smooth() function, one for each group of Awareness. We use the subset() function to create a separate dataset for the second group of Awareness (greater than 3). We also use the scale_color_manual() function to assign colors to the two groups of data. Finally, we add a title and axis labels using the labs() function.

R Scatterplot with Regression Lines for Two Awareness Groups

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

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