I have several plots, for which I create linear geom_line models, however, I wish to force the geom_line through (0,0) and I can't seem to figure out how to do it.
Im using ggplot on a dataframe, and then using geom_line to create two linear correlations for two samples within the dataframe. With the following code
ggplot(df_test,aes(x=xval, y=yval)) +
geom_point(aes(color = Samples)) +
scale_color_manual(values = c("Sample1" = 'black','Sample2'='red')) +
geom_smooth(data=df_test[df_test$Samples == "Sample1",],
method=lm,color="black",formula= (y~poly(x,1)),se=F) +
geom_smooth(data=df_test[df_test$Samples == "Sample2",],
method=lm,color="red",formula= (y~poly(x,1)),se=F) +
geom_text(aes(label=Chromosome,color=Samples),hjust=0.2, vjust=-0.5) +
labs (y="yval") +
labs(x="xval") +
theme_bw()
Which yields the following image
Ideally the black line should be forced to pass through (0,0)
And I've tried to use something similar to Force the origin to start at 0
scale_x_continuous(breaks = seq(0, 12, 1)
scale_x_continuous(expand = c(0, 0)) + scale_y_continuous(expand = c(0, 0))
But it doesnt work. Is it even possible with ggplot? If so can anyone help with this problem? Thanks a lot