[R] How to add legend of plot.Design function ( method=image)?

From: Jan Verbesselt <Jan.Verbesselt_at_biw.kuleuven.be>
Date: Tue 23 Aug 2005 - 00:58:48 EST

 

Dear Rlist,  

How can the Legend of the plot.Design() function can be visualized?  

Following the documentation in R, I did the following (see below), only the 'Legend' function doesn't visualize the legend of the

plot (method='image') of the lrmfit. I tried to change par( margin setting) but this didnít solve it.  

How can this be solved?  

Thanks a lot,

Jan    

library(Design)

     n <- 1000 # define sample size

     set.seed(17) # so can reproduce the results

     age <- rnorm(n, 50, 10)

     blood.pressure <- rnorm(n, 120, 15)

     cholesterol <- rnorm(n, 200, 25)

     sex <- factor(sample(c('female','male'), n,TRUE))

     label(age) <- 'Age' # label is in Hmisc

     label(cholesterol) <- 'Total Cholesterol'

     label(blood.pressure) <- 'Systolic Blood Pressure'

     label(sex) <- 'Sex'

     units(cholesterol) <- 'mg/dl' # uses units.default in Hmisc

     units(blood.pressure) <- 'mmHg'  

     # Specify population model for log odds that Y=1

     L <- .4*(sex=='male') + .045*(age-50) +

       (log(cholesterol - 10)-5.2)*(-2*(sex=='female') + 2*(sex=='male'))

     # Simulate bin

     ary y to have Prob(y=1) = 1/[1+exp(-L)]

     y <- ifelse(runif(n) < plogis(L), 1, 0)  

     ddist <- datadist(age, blood.pressure, cholesterol, sex)

     options(datadist='ddist')  

     fit <- lrm(y ~ blood.pressure + sex * (age + rcs(cholesterol,4)),

                    x=TRUE, y=TRUE)

 

    boundaries <- perimeter(age, cholesterol, lowess=TRUE)

    plot(age, cholesterol) # show bivariate data density

    lines(boundaries) # and perimeter that will be used for 3-D plot

    z <- plot(fit, age=NA, cholesterol=NA, perim=boundaries, method='image')

# draws image() plot

# don't show estimates where data are sparse

# doesn't make sense here since vars don't
interact

    if(!.R.)Legend(z, fun=plogis, at=qlogis(c(.01,.05,.1,.2,.3,.4,.5)), zlab='Probability') # gray scale or color legend for prob.  



Ir. Jan Verbesselt
Research Associate
Group of Geomatics Engineering
Department Biosystems ~ M≥-BIORES
Vital Decosterstraat 102, 3000 Leuven, Belgium Tel: +32-16-329750 Fax: +32-16-329760
http://gloveg.kuleuven.ac.be/
 

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Aug 23 01:10:37 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:55 EST