Closed DemaLM closed 6 years ago
geom_point
. If you don't want visreg
to plot the partial residuals, the option is partial=FALSE
. So, for example:visreg(fit, "Time", ylab="Protein", gg=TRUE, partial=FALSE, rug=FALSE) +
theme_bw() +
geom_point(size=3, alpha=0.1, shape=16)
by
and overlay
arguments:visreg(fit, "Time", ylab="Protein", gg=TRUE, by="Diet", overlay=TRUE)
visreg
's plotting of points and plot them yourself, you can, but (a) this would need to be done through the aes
interface in ggplot2
and (b) you still need to set up a by
variable, otherwise it won't be included in the data frame that ggplot2
is based on:visreg(fit, "Time", ylab="Protein", gg=TRUE, by="Diet", overlay=TRUE, partial=FALSE, rug=FALSE) +
theme_bw() +
geom_point(aes(color=Diet), size=3, alpha=0.1, shape=16)
visreg
via points.par
:visreg(fit, "Time", ylab="Protein", gg=TRUE, by="Diet", overlay=TRUE,
points.par=list(size=3, alpha=0.1), jitter=TRUE)
Thank you very much for your help! One last thing: I understood your last two examples to use Diet to color the points, however, is it possible to use a variable which is not specified in the model to color the points? For example, if there were a "Farm.ID" variable in the Milk dataset and I'd like to use it as a grouping variable to color the points according to this variable.
Thanks
You can do it, although you would have to manually add the variable to the visreg object; otherwise, if the variable isn't in the model frame, visreg
doesn't have access to it. For example:
fit <- lmer(protein ~ Time + (Time|Cow), Milk)
v <- visreg(fit, "Time", ylab="Protein", jitter=TRUE, plot=FALSE)
v$res$Diet <- Milk$Diet
plot(v, gg=TRUE, partial=FALSE, rug=FALSE) + theme_bw() +
geom_point(data=v$res, aes(x=Time, y=visregRes, color=Diet), size=3, alpha=0.1, shape=16)
That's exactly what I wanted! Thank you very much!!!
Happy to help!
Hi,
I'd like to have specific colors for groups in my points in the visreg output.
So for instance, taking the mixed model example:
In this case, I don't know why are there dots in the middle of the points. Just can't remove them. Second, I'd color the points with specific colors for Diet using ggplot as above .
Many thanks!