Adding predict line from glm to ggplot2, larger than original data set

Viewed 4592

I have included a sample data set just to demonstrate what I am trying to do.

Speed <- c(400,220,490,210,500,270,200,470,480,310,240,490,420,330,280,210,300,470,230,430,460,220,250,200,390)

Hit <- c(0,1,0,1,0,0,1,0,0,1,1,0,0,1,1,1,1,1,0,0,0,1,1,1,0)

obs <- c(1:25)

msl2.data <- as.data.frame(cbind(obs,Hit,Speed))

msl2.glm <- glm(Hit ~ Speed, data = msl2.data, family = binomial)

Doing What I want in the base package.

plot(Hit~ Speed, data = msl2.data, xlim = c(0,700), xlab = "Speed", ylab = "Hit", main = "Plot of hit vs Speed")

pi.hat<-(predict( msl2.glm, data.frame(Speed=c(0:700)), type="response" ))

lines( 0:700, pi.hat, col="blue" )

I am trying to recreate the above plot, but in ggplot. The error I have been unable to work around is the aes(x,y) have different lengths, which is true, but I want them to have different lengths.

Any ideas for this in gg?

1 Answers
Related