I'm attempting to plot some lines based upon coefficients from some lmer model fits to some ggplot facets. I'd like to plot a different line for each facet. What would be the best way of achieving this?
To obtain my fits, I'm using the following approach, as it's a binomial lmer model:
model.coefs <- fixef(model)
curve( invlogit( cbind(1, x) %*% model.coefs ), add=TRUE )
This is taken from this question. When saved to a variable, the curve function gives a bunch of x and y co-ordinates that I'd like to plot on my graphs.
I'm able to get it to produce a decent plot using the base R graphing functions, but I'd rather go for ggplot instead. So, rather than do this to get two different plots for two different models, labelled here as modelA and modelB:
plot(x, y)
modelA.coefs <- fixef(modelA)
curve( invlogit( cbind(1, x) %*% modelA.coefs ), add=TRUE )
plot(x, y)
modelB.coefs <- fixef(modelB)
curve( invlogit( cbind(1, x) %*% modelB.coefs ), add=TRUE )
I'm trying to get it working in ggplot instead.
ggplot(dataset)+
aes(x=x, y=y)+
geom_point()+
facet_wrap(~groupingFactor)+
geom_line(subset(dataset, groupFactor=="factorA"), **[would the solution be to feed this line something here?]**)
I suspect part of the problem is my trying to mangle together several examples at once (including this one, this one, and this one), but this feels like it should be simple to work out. What is it I'm doing wrong or missing here?