ProjectMOSAIC / mosaic

Project MOSAIC R package
http://mosaic-web.org/
93 stars 26 forks source link

create replacement for plot.lm()? #321

Closed rpruim closed 10 years ago

rpruim commented 10 years ago

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.

nicholasjhorton commented 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

ramnathv commented 10 years ago

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.

rpruim commented 10 years ago

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:

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.

rpruim commented 10 years ago

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:

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")

image image

Hmm. I should label that 7th plot with the confidence level used -- should be relatively easy to do.

rpruim commented 10 years ago

For mplot(lm(...)) we should decide

rpruim commented 10 years ago

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.

image

image