# Regression Lines With Same Intercept

So, I struggle with Regression a lot. I just found out how to get 2 lines with the same slope, but I cannot manage to get 2 lines with the same intercept. I read about ANCOVA a lot (because I thought this was what I needed), but no one uses the same intercepts; just the same slope. Can someone help out with this?

-
what have you tried? – Justin Oct 11 '12 at 16:39
lm(y~x+f:x) ... – Ben Bolker Oct 11 '12 at 16:51
how do I plot this? – cups Oct 11 '12 at 17:24

## migrated from stackoverflow.comOct 11 '12 at 19:31

library(ggplot2)
set.seed(1)
x <-  1:10
dd <- rbind(data.frame(x=x,fac="a", y=x+rnorm(10)),
data.frame(x=2*x,fac="b", y=x+rnorm(10)))
coef <- lm(y~x:fac, data=dd)$coefficients qplot(data=dd, x=x, y=y, color=fac)+ geom_abline(slope=coef["x:faca"], intercept=coef["(Intercept)"])+ geom_abline(slope=coef["x:facb"], intercept=coef["(Intercept)"])  -  I have a indicator variable ky which takes values 1 and 2, but if I try to do ["x:ky1"] it says that object does not exist. What am I missing? – cups Oct 12 '12 at 1:17 look at the names of lm(y~x:fac, data=dd)$coefficients – jem77bfp Oct 12 '12 at 6:15