Skip to content

Instantly share code, notes, and snippets.

@cdesante
Created June 20, 2012 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdesante/2961057 to your computer and use it in GitHub Desktop.
Save cdesante/2961057 to your computer and use it in GitHub Desktop.
Scatter Plots + lines by Group
library(ggplot2)
FEM <- c(rep(1, 100), rep(0, 100))
Gender <- c(rep("Female", 100), rep("Male", 100))
pid7 <- sample(0:6, 200, replace=T)
Bfem <- rnorm(200, 1.94, 0.37)
Bpid <- rnorm(200, -1.45, 0.82)
Binter <- rnorm(200, 0.31, .11)
B0 <- rnorm(200, 74.2, .29)
DV <- B0 + Bfem*FEM + Bpid*pid7 + (FEM*pid7)*Binter
P <- qplot(pid7, DV, geom="jitter", colour=Gender, shape=Gender)
P1 <- P + geom_abline(intercept = 74.27, slope = -1.45, colour="dodgerblue", size=2, lty=4 )
P1 + geom_abline(intercept = 74.27+1.94, slope = -1.45+.31, colour="deeppink", size=I(2), lty=3) + theme_bw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment