You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The R convention is that print() should return the original object invisibly. In base R, plotting is just a side effect, and the plot object cannot be saved. ggplot changes the latter behavior and has functions that produce objects of class "ggplot", which has corresponding plot and print methods to actually render the plot. These methods follow the convention that print() should return the original object invisibly (the object here being the plot).
see currently sits somewhat awkwardly between these two conventions. When the print() method is called for objects of class see_*, the various plots are generated and rendered, then the original object is returned (not the plot). What makes this feel awkward is that, although the plots are ggplots, they are never returned as objects, so users cannot extend them further.
The awkwardness goes a little further in that we don't currently make much distinction between, eg., model check results from check_model() and the plots of those results. So a user might expect to be able to do something like this:
library(performance)
library(ggplot2)
library(see)
m <- lm(mpg ~ hp, data = mtcars)
cc <- check_model(m)
cc + theme_bw()
I don't think we can reasonably change the whole underlying class dispatch for easyverse functions, but I think we really should make it possible for a user to get to a place where standard ggplot conventions apply.
Here's my idea. I suggest we extend the API to have parallel print() and plot() methods for each class. print() will continue the current behavior--generate whatever output and plots, return the original data. plot() however will generate the plots and return them as "ggplot" or "patchwork" objects. This would enable:
library(performance)
library(ggplot2)
library(see)
m <- lm(mpg ~ hp, data = mtcars)
cc <- check_model(m)
plot(cc) + theme_bw()
Edit: fixed example code based on Daniel's comments.
The text was updated successfully, but these errors were encountered:
I'm integrating performance in a R package which uses several OLS regressions to test statistical mediation (JSmediation) in order to provide helpers to check assumptions. I'd love to provide helpers to show the diagnostic plots of the several underlying models.
Right now, I cannot edit the plot produced by see to add, for example, a title, but I'd love too!
I have the feeling that the feature offered here would help a lot such integration of see in other packages.
The R convention is that
print()
should return the original object invisibly. In base R, plotting is just a side effect, and the plot object cannot be saved. ggplot changes the latter behavior and has functions that produce objects of class"ggplot"
, which has correspondingplot
andprint
methods to actually render the plot. These methods follow the convention thatprint()
should return the original object invisibly (the object here being the plot).see currently sits somewhat awkwardly between these two conventions. When the
print()
method is called for objects of classsee_*
, the various plots are generated and rendered, then the original object is returned (not the plot). What makes this feel awkward is that, although the plots are ggplots, they are never returned as objects, so users cannot extend them further.The awkwardness goes a little further in that we don't currently make much distinction between, eg., model check results from
check_model()
and the plots of those results. So a user might expect to be able to do something like this:I don't think we can reasonably change the whole underlying class dispatch for easyverse functions, but I think we really should make it possible for a user to get to a place where standard ggplot conventions apply.
Here's my idea. I suggest we extend the API to have parallel
print()
andplot()
methods for each class.print()
will continue the current behavior--generate whatever output and plots, return the original data.plot()
however will generate the plots and return them as"ggplot"
or"patchwork"
objects. This would enable:Edit: fixed example code based on Daniel's comments.
The text was updated successfully, but these errors were encountered: