[R] rms plot.Predict when type="p"

Frank Harrell f.harrell at Vanderbilt.Edu
Fri Aug 2 18:31:41 CEST 2013


Mike, 2 out of 3 of your requests are handled simply.  I've tidied up 
your code and show how to include extra parameters into the plot( ) call 
below.  The request to change plotting symbol color for each factor 
level is not consistent with the lattice philosophy for non-superposed 
variables (here on the x-axis) where the labels tell all.  The last 2 
lines in the code uses superpositioning for group but the col argument 
affects the color of confidence bands; I didn't look into that further.

Frank Harrell
----------
require(rms)
n     = 30
group = factor(sample(c('a','b','c'), n, TRUE))
x1    = runif(n)
dat   = data.frame(group, x1,
                    y = as.numeric(group) + 0.2*x1 + rnorm(n) )

d <- datadist(dat) ; options(datadist="d")

f <- ols(y ~ x1 + group, data=dat)
p <- Predict(f, group)
plot(p, ~group, nlines=TRUE, type='p', ylab='fitted Y', xlab='Treatment',
      pch=4, lwd=3)
p <- Predict(f, x1=seq(0,1,by=.1), group)
plot(p, ~ x1, groups='group', col=3:1)

----------

Hi all,

I'm trying to change the pch, color, lty, and lwd in a type="p" plot
produced by plot.Predict in the rms package.  What I'm shooting for is a
separate plotting symbol symbol color for each level of a factor (and also
to manage the line width for the CIs).

Here's what I hope is a working example

#make up some data
. . .
Mike Babyak
Department of Psychiatry and Behavioral Sciences



More information about the R-help mailing list