R Scatterplot with Regression Lines for Two Groups of Awareness
Assuming that you have two variables named 'group1' and 'group2' in your dataset, here is how you can make a scatterplot of the two groups of awareness and add the two regression lines to the plot using R:
# Load the ggplot2 package
library(ggplot2)
# Create a dataframe with the two groups of awareness
df <- data.frame(group1 = c(2, 3, 4, 5, 6), group2 = c(1, 2, 3, 4, 5))
# Create a scatterplot of the two groups of awareness
ggplot(df, aes(x = group1, y = group2)) +
geom_point() +
xlab('Group 1 Awareness') +
ylab('Group 2 Awareness') +
ggtitle('Scatterplot of Two Groups of Awareness')
# Add the two regression lines to the plot
ggplot(df, aes(x = group1, y = group2)) +
geom_point() +
xlab('Group 1 Awareness') +
ylab('Group 2 Awareness') +
ggtitle('Scatterplot of Two Groups of Awareness') +
geom_smooth(method = 'lm', se = FALSE, color = 'red') +
geom_smooth(aes(x = group2, y = group1), method = 'lm', se = FALSE, color = 'blue')
In the above code, we first load the ggplot2 package. Then, we create a dataframe named 'df' with the two groups of awareness. We use ggplot() function to create a scatterplot of the two groups of awareness, where we specify the x and y variables as 'group1' and 'group2', respectively. We also add labels to the x and y axes and a title to the plot.
To add the two regression lines to the plot, we use the geom_smooth() function twice. The first time, we specify the method as 'lm' (linear regression) and the color as 'red' to add the regression line for 'group1' vs 'group2'. The second time, we specify the x and y variables as 'group2' and 'group1', respectively, and the color as 'blue' to add the regression line for 'group2' vs 'group1'. We also set the se argument to FALSE to remove the confidence intervals around the lines.
原文地址: https://www.cveoy.top/t/topic/kAwD 著作权归作者所有。请勿转载和采集!