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));
}
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")