Last active
August 29, 2015 14:22
-
-
Save anghyflawn/c794887b637d0af74702 to your computer and use it in GitHub Desktop.
Example of visreg output plotted with ggplot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# library(visreg) | |
# library(mgcv) | |
# library(dplyr) | |
fit <- gam(v1h.v2h.ratio ~ s(v2h.dur, by=v1, k=5) + | |
v1 + v1.is.long + s(speaker, bs='re') + s(word, bs='re'), | |
data=sw.data) | |
v <- visreg(fit, xvar='v2h.dur', by='v1') | |
# Some advantages of using ggplot2 here: | |
# - Consistency with other plots | |
# - Control over display (as in the plotting of residuals here) | |
# - Control over what gets shown (here the model includes a set of observations where | |
# v1 is \\sw but don't really want that plotted) | |
ggplot(filter(v$fit, v1 != '\\sw'), aes(v2h.dur, visregFit))+ | |
geom_line(colour='blue', size=1)+ | |
geom_ribbon(aes(ymin=visregLwr, ymax=visregUpr), alpha=.3)+ | |
geom_point(data=filter(v$res, v1 != '\\sw'), aes(v2h.dur, visregRes), size=1, alpha=.3)+ | |
xlab('Duration of post-tonic vowel')+ | |
ylab('Effect on V1/V2 ratio')+ | |
facet_wrap(~v1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment