Closed jebyrnes closed 5 years ago
This is a good point; on a deeper level, the issue is that various visreg commands (including but not limited to visreg(fit, gg=TRUE)
) produce an object of type visregList
(a list of visreg objects). But plot.visregList
does not (yet) work with ggplot2
.
Thank you for bringing this to my attention; I'm kind of busy the next few weeks, but I hope to fix this soon.
No worries! I hadn't even realized that you could use this with ggplot2
until just a few days ago. I was absolutely delighted, as I'm teaching an intro data science class that is all ggplot2
all the time, and had been sad I couldn't use visreg... until I discovered a few posts saying I could! I tried to poke into the codebase myself, but, don't have the time to get a deep understanding and make the fixes myself.
Sidenote: I wonder if there's an argument where instead of kicking back a visregLis
t object, visreg could just return a tidy long data frame? Might be a way to allow for longevity if some hot new graphing package came up to avoid similar questions. Heck, like using plotly or somesuch? Just a thought that popped into my head.
Thank you for a wonderful package - it's my goto for teaching multiple linear regression!!! Students love it!
I was wondering if this problem had been fixed, because I am having the same issue.
OK, just committed a change that fixes this issue. To clarify (continuing the above example), this has always worked fine:
# CRAN release: install.packages('visreg')
v <- visreg(fit, plot=FALSE)
plot(v, gg=TRUE)
However, with the new release, this also works:
# Current GitHub version: devtools::install_github("pbreheny/visreg")
visreg(fit, gg=TRUE)
Thanks to both of you for bringing this to my attention -- sorry for the delay in fixing this. Please let me know if you're still having issues or notice anything else!
By the way, just to respond to @jebyrnes above, visreg
can't exactly return a tidy data frame because it needs to return two data frames, one for the fit/confidence intervals and a different one for the residuals. These are returned:
v <- visreg(fit, 'x')
The two data frames are v$fit
and v$res
. You can take those data frames and edit them, manipulate them in various ways, assign them to various aesthetics in the plot (if you know what you're doing). I've been meaning to investigate how easy it is to pipe visreg output to plotly
, but haven't gotten around to it. I think it should be easy, since plotly can handle gg objects, but haven't actually tried it yet.
I'm a huge fan of how visreg works with ggplot. So, the default example of
Is awesome.
However,
produces nothing. I can understand that perhaps having different variables requires some more variable transformation. But, it's still frustrating to have nothing happens - as a user, it makes me think I did something wrong. Might I suggest either
gg=TRUE
works for multiple continuous variables, I'm guessing you have something similar built there?