Is R squared biased against flat lines? R squared is calculated by doing 1 minus the the squared error of the predicted line divided by the squared error of the y mean line. When the line is flat, the y mean will have a squared error of close to zero, because the y mean line is also flat. Because of the low squared error from the y mean line, the R squared of the predicted line will be low, even though the line might fit the data well. Why is R squared lower on flatter lines disregarding the quality of those lines?
 A: $R^2$ being zero for flat lines is not a bias: is just what it is intended to be. I'll give two reasons.
First reason is that $R^2$ measures if there is a linear relationship between two variables. A relationship would mean that the values we can expect from one variable depend on the value of the other variable. If the variables are related by a flat line, the value of one variable is always the same, it doesn't depend on the value of the other variable and there is no linear relationship between both variables. $R^2$ being zero or very small just shows it.
The second reason is that a flat line is a line just because of scale. If points are not exactly aligned, changing the scale of the vertical axe shows the difference between the points and the line and the scatterplot becomes a cloud and not a line.
Here is a graphical example:

In the bottom and right plots, points are clearly aligned, while upper left plot shows no relationship between the variables. However, all of them are just the same plot with different graphical scales.
I copy here the R code just for reproductibility of the plots.
set.seed(1)
x<-rnorm(100)
y<-rnorm(100)
par(mfrow=c(2,2))
plot(x,y)
plot(x,y,xlim=c(-100,100))
plot(x,y,ylim=c(-100,100))
cor(x,y)^2

A: Remember that $R^2$ is measuring the quality of a model relative to a baseline model. The baseline model is the $y$ mean model -- which simply reports the mean of all the responses, disregarding any information contained in the predictors. If $R^2$ is zero for a particular model, this means that the model is no better than the baseline model ("no better" in the sense that the predictions offered by the model have the same squared error as those produced by the baseline model ).
If the best fitting linear model turns out to have zero slope, then of course it is no better than the baseline model, since an intercept-only model will return the mean of the responses as the least-squares fit. So we should not be surprised that $R^2$ is zero for flat line models.
Comparing two linear models, all else being equal (in particular having the same error variance), the model with a flatter slope will have smaller $R^2$ because its predictions are closer to what the baseline model -- a straight mean of the responses -- would return.
A: In fact, when you have a cloud of points that seems to follow (very well) a flat line (vertical or horitzontal), you could not know a priori if the correlation is good or bad. Just zoom in the axe where the variable 'seems' to be constant and check whether there is correlation or not.
