I ran an linear regression with the following commands:
lm.intp <- lm(intp.trust~age,data=Scountry)
And then i hope to draw a scatterplot to compare the residuals of different genders. i use the Scountry$res <- lm.intp$residuals
commands to put the regression residuals into the data frame, and then use ggplot to draw the scatterplot. But when i run Scountry$res <- lm.intp$residuals
, it keep saying the existing data and assigned data have different rows. how can i avoid this situation?
And when i draw the scatterplot, i hope to use the following commands:
ggplot(Scountry, aes(x=, y=res, color=as.factor(gender))) +geom_point()
I know that in this plot, y should be the residuals, and the x should be the observations of this data, but i really have no idea what should be wrote in "x=" since the observations in my data have no ID, it's look like this:
Could anyone please help me solve this questions? i'd be really appreciated!