Hi,
I was trying to include a background annotation in a ggplot but for some reason it throws the discrete value supplied to continous scale error.
if we add a geom blank before annotation it works ( but then the scales limit will depend on whatever data we map to geom blank which is not desired as we want the plot to only show the smooth)
Is there another way to let the annotation start/end from to the plot edges for discrete scales?
require(ggplot2)
#> Loading required package: ggplot2
mtcars$cylf<- as.factor(mtcars$cyl)
ggplot(mtcars, aes(x=cylf, 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 0.99
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : neighborhood radius 2.01
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : reciprocal condition number 2.0055e-016
#> Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
#> parametric, : There are other near singularities as well. 4.0401
#> 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 0.99
#> 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
#> 2.01
#> 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-016
#> 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. 4.0401
ggplot(mtcars, aes(x=cylf, y=mpg))+
annotate("rect", xmin = -Inf, xmax = Inf,
ymin = 15,ymax = 30,fill="lightblue")+
geom_smooth(aes(group=-1L) )
#> Error: Discrete value supplied to continuous scale
Created on 2019-03-13 by the reprex package (v0.2.1)