Dimitri Liakhovitski
2009-Feb-10 21:20 UTC
[R] Putting values and axis X labels on the charts based on allEffects
Dear everybody! Need help with graphics. I am runnig a simple lm and then using allEffects from 'effects' package: require(effects) model<-lm(Y~A+B, data=mydataframe) I am trying to build (for each predictor - A and then B) a plot of means on Y. I was successful doing it like this - in one swoop: ml.eff<-allEffects(ml1, se=F) plot(ml.eff,ylab="Title of Y") Is it possible to show on my graph: 1. The actual Y values for each dot. 2. The title for A on the A graph and the title for B on the B graph - but without having to do it one by one - because in reality I have more predictors than one. Thank you very much! -- Dimitri Liakhovitski MarketTools, Inc. Dimitri.Liakhovitski at markettools.com
John Fox
2009-Feb-10 22:01 UTC
[R] Putting values and axis X labels on the charts based on allEffects
Dear Dimitri,> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]On> Behalf Of Dimitri Liakhovitski > Sent: February-10-09 4:21 PM > To: R-Help List > Subject: [R] Putting values and axis X labels on the charts based on > allEffects > > Dear everybody! > Need help with graphics. I am runnig a simple lm and then using > allEffects from 'effects' package: > > require(effects) > model<-lm(Y~A+B, data=mydataframe) > > I am trying to build (for each predictor - A and then B) a plot of meanson> Y. > I was successful doing it like this - in one swoop: > > ml.eff<-allEffects(ml1, se=F) > plot(ml.eff,ylab="Title of Y")Just to be clear, what you're getting is a plot of predicted values of Y at levels of A (or values of A, depending upon whether A is a factor or numeric), holding B constant at its mean (or proportional distribution in the data, depending upon whether B is numeric or a factor). Similarly for B given A.> > Is it possible to show on my graph: > 1. The actual Y values for each dot.Yes, it's possible, but you'd have to make a custom graph to do it. allEffects() returns a list of effect objects corresponding to the high-order terms of the model (here A and B), each of which contains all of the information you need to make the plot. To see what's there, try, e.g., str(ml.eff); to see the effect object for A, try str(m1.eff[["A"]]).> 2. The title for A on the A graph and the title for B on the B graph - > but without having to do it one by one - because in reality I have > more predictors than one.Do you mean more predictors than 2? In any event, to customize the main title, you'd have to make the plots individually. You could automate this, however, by a loop, looping over names(m1.eff). More generally, the plot methods for effect objects try to behave reasonably and to provide reasonable flexibility but aren't really meant to produce publication-quality graphs. I hope this helps, John> > Thank you very much! > > > -- > Dimitri Liakhovitski > MarketTools, Inc. > Dimitri.Liakhovitski at markettools.com > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.