Closed rpruim closed 10 years ago
I think that this would be a useful addition, given how commonly plot.lm() is used. And I know that it induces some confusion about base graphics vs. lattice for intro students.
Just my $0.02,
Nick
On May 31, 2014, at 10:21 AM, Randall Pruim notifications@github.com wrote:
It currently produces base graphics plots. We could provide a version that does lattice and/or ggplot2 plots. I can't decide if this is worth the effort.
— Reply to this email directly or view it on GitHub.
Nicholas Horton Professor of Statistics Department of Mathematics and Statistics, Amherst College Box 2239, 31 Quadrangle Dr Amherst, MA 01002-5000 https://www.amherst.edu/people/facstaff/nhorton
The code here is a good starting point. I remember vaguely having seen an autoplot
package that provides ggplot2 replacements for common plot methods, but cannot place it.
I think autoplot()
is a generic function in ggplot2
with essentially no methods. It is there (together with fortify()
to suggest a particular framework for creating such functions. I don't know how many/which packages out there have taken advantage of this.
Issues for us:
fortify()
is fine, since step 2 could go either toward ggplot2
or lattice
(or eventually ggvis
). autoplot()
is intended to create ggplot2
graphics. We could use mplot()
and fold in our current mPlot()
which would handle the case when a data frame is provided as input. That is perhaps better than masking plot()
.Note: There already are some beginnings of this in my fastR::xplot()
. But it is probably worth starting from scratch if we are going to do this since I know that xplot()
has some issues.
I've done this and more. I've created a new function called mplot()
that is a generic like plot()
. So far this is what it knows how to handle:
mPlot()
which we might want to stop exporting and perhaps rename?)These can be asked to make either ggplot2
or lattice
plots. Still testing and documenting, but I expect this will be in the beta branch soon.
Examples:
mplot( lm(width ~ length * sex, data=KidsFeet), which=1:7, ncol=3)
mplot( lm(width ~ length * sex, data=KidsFeet), which=c(1:5,7),
ncol=3, system="ggplot2")
Hmm. I should label that 7th plot with the confidence level used -- should be relatively easy to do.
For mplot(lm(...))
we should decide
I think I'm pretty much ready to sign off on this project. I've added the coefficient plot to the mix. We could add another plot if there was a reasonable one to add. The default makes for of these. By default they are combined into a single plot like the ones below, but one can receive them as a list of separate plots if one prefers.
Interestingly, in the example below, the ggplot2
smoother doesn't do a very good job compared to the lattice
version.
It currently produces base graphics plots. We could provide a version that does lattice and/or ggplot2 plots. I can't decide if this is worth the effort.