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

From: Jan Verbesselt <>
Date: Tue 23 Aug 2005 - 06:58:13 EST


When running  

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

Legend(z, fun=plogis, at=qlogis(c(.01,.05,.1,.2,.3,.4,.5)), zlab='Probability')  

 And after pointing the cursor to the plot() screen in R, I obtain the following message:  

Using function "locator(2)" to place opposite corners of image.legend

Error in Legend.plot.Design(z, fun = plogis, at = qlogis(c(0.01, 0.05, :

        couldn't find function "subplot"  

*How can I position the legend inside the range? (or solve the following error message).  



-----Original Message-----
From: Jan Verbesselt [] Sent: Monday, August 22, 2005 4:59 PM
To: ''
Subject: How to add legend of plot.Design function ( method=image)?    

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,



     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)


     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

    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

        [[alternative HTML version deleted]] mailing list PLEASE do read the posting guide! Received on Tue Aug 23 07:02:04 2005

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