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

Frank E Harrell Jr f.harrell at vanderbilt.edu
Mon Aug 22 23:15:42 CEST 2005


Jan Verbesselt wrote:
> Hi,
> 
>  
> 
> 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).
> 
>  
> 
> Regards,
> 
> Jan

The if(!.R.) in the example code was for a reason: I couldn't find 
subplot in R.  If you want to provide code enhancements to do this I 
will incorporate your new code. -Frank

> 
>  
> 
>  
> 
>  
> 
> -----Original Message-----
> From: Jan Verbesselt [mailto:Jan.Verbesselt at biw.kuleuven.be] 
> Sent: Monday, August 22, 2005 4:59 PM
> To: 'r-help at stat.math.ethz.ch'
> 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,
> 
> 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 at 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


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




More information about the R-help mailing list