[R] Cbind() on the right-side of a formula in xYplot()

Frank E Harrell Jr f.harrell at vanderbilt.edu
Mon Oct 26 19:23:14 CET 2009


Dylan Beaudette wrote:
> Hi,
> 
> Using the latest rms package I am able to make nice plots of model predictions 
> +/- desired confidence intervals like this:
> 
> # need this
> library(rms)
> 
> # setup data
> d <- data.frame(x=rnorm(100), y=rnorm(100))
> dd <- datadist(d)
> options(datadist='dd')
> 
> # fit model
> l <- ols(y ~ rcs(x), data=d)
> 
> # predict along original limits of data
> l.pred <- Predict(l)
> 
> # plot of fit and conf. int.
> xYplot(Cbind(yhat, lower, upper) ~ x, data=l.pred, method='filled', 
> col.fill=grey(0.9), col=1, type='l')
> 
> Is there any way in which I can turn this figure on its side, by plotting x ~ 
> y... something like this:
> 
> # doesn't work
> xYplot(x ~ Cbind(yhat, lower, upper), data=l.pred, method='filled', 
> lable.curves=FALSE, col.fill=grey(0.9), col=1, type='l')
> 
> # standard lattice, but without the fancy filled area
> xyplot(x ~ yhat + lower + upper, data=l.pred, type='l', lty=c(1,2,2), col=1)
> 
> Any suggestions? If it is not possible, then I will try and manually make the 
> figure with basic lattice functions.
> 
> Cheers,
> Dylan
> 
> 

Dylan,

Cbind is for the left hand side of the formula.  I suggest you look at 
one of the books that covers lattice graphics, or the online resources 
for lattice to customize this.  The output from Predict is suitable for 
several graphics models.

Frank

-- 
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University




More information about the R-help mailing list