0

I try to facet_wrap my picture by 2 by 2. There is this error when I try to change facet_grid to facet_wrap:

Error in layout_base(data, vars, drop = drop) : At least one layer must contain all variables used for facetting

I also have not been able to put the linear equation in there. Would you please help? My data is wt2, x-axis is IR and y-axis is GLSEA and I plot it by SEASON.

m_eqn <- function(wt2) {
            m = lm(IR ~ GLSEA, wt2);
            eq <- substitute(italic(y) == a + b %.% italic(x)*","~~italic(r)^2~"="~r2, 
            list(a = format(coef(m)[1], digits = 2), 
            b = format(coef(m)[2], digits = 2), 
            r2 = format(summary(m)$r.squared, digits = 3)))
            as.character(as.expression(eq));                 
            }

enter image description here

p <- ggplot(wt2, aes(x = IR, y = GLSEA, colour = SEASON)) + 
geom_point(shape = 1) + 
xlab("Water temperature ºC (IR measurement)") +
ylab("Water Temperature ºC (GLSEA)") + 
ylim(-10,25) + 
xlim(-10,25) +
scale_colour_hue(l=50) + 
geom_smooth(method=lm, se=FALSE, fullrange=TRUE) +
theme(strip.text.x = element_text(size=12, face ="bold")) + 
facet_wrap(. ~ SEASON) + 
coord_fixed() +
geom_abline(intercept = 0,slope =1,linetype="dashed")
Karolis Koncevičius
  • 9,417
  • 9
  • 56
  • 89
jen
  • 31
  • 1
  • 4
  • 1
    Please make your example minimal and reproducible. [See here.](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Axeman Mar 23 '16 at 14:19
  • 2
    My guess is that you have to remove the `.` from your `facet_wrap` call. – Axeman Mar 23 '16 at 14:21

0 Answers0