Understanding when and why Discrete value supplied to continuous scale happens

This is happening because you're converting cylinders to a factor (discrete), but you'll still get warnings from geom_smooth() using the default method, because you can't really apply loess to categorical data (which is what factors are/why you encoded cylinder as factors — you can't have part of a cylinder):

library(ggplot2)

ggplot(mtcars, aes(x = cyl, y = mpg)) +
  geom_blank() +
  annotate("rect",
    xmin = -Inf, xmax = Inf,
    ymin = 15, ymax = 30, fill = "lightblue"
  ) +
  geom_smooth(aes(group = -1L))
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : pseudoinverse used at 3.98
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : neighborhood radius 4.02
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : reciprocal condition number 2.0055e-16
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : There are other near singularities as well. 16.16
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : pseudoinverse used
#> at 3.98
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : neighborhood radius
#> 4.02
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : reciprocal
#> condition number 2.0055e-16
#> Warning in predLoess(object$y, object$x, newx = if
#> (is.null(newdata)) object$x else if (is.data.frame(newdata))
#> as.matrix(model.frame(delete.response(terms(object)), : There are other
#> near singularities as well. 16.16

Created on 2019-03-13 by the reprex package (v0.2.1)

This Stack Overflow thread might be helpful:

1 Like