[R] Multiple rms summary plots in a single device

Mike Harwood harwood262 at gmail.com
Fri May 25 16:16:55 CEST 2012


I would like to incorporate multiple summary plots from the rms
package into a single device and to control the titles, and also to
open a new device when I reach a specified number of plots.  Currently
I am only getting a single "plot(summary(" graph in the upper left-
hand corner of each successive device.  However, in the rms
documention I see instances of a loop being used with "par(mfrow(" for
multiple plots in a single device(e.g. residuals.lrm), and these
examples work on my system.  Please advise regarding options that must
be specified to "plot(summary(", or in the construction of my loop.
Below are sample code and my sessionInfo().  Please note that I am
using data.table to facilitate my "real analysis", but I can replicate
the issue with tData as a data.frame (using seg <- subset(tData,
groups == segment) logic), but I included the data.table logic in case
it may be having some influence.  Thank you!

Mike


tData <- data.frame(groups=as.factor(1:8), low=as.factor(1:4)
	,high=as.factor(seq(100, 400, 100)),  rand=runif(400))
tData <- data.table(tData)
setkeyv(tData, 'groups')


dd <- datadist(tData)
options(datadist = 'dd')

doSumPlot <- function(segment){
	seg <<- tData[groups == segment,]
	plot(summary(rand ~
			+ low
			+ high
		,data = seg
		), main=paste('Group:', segment))
}


for(i in 1:length(levels(tData$groups))){
	cat('Group: ', i, '\n')
	if(i == 1 ){
		dev.new()
		par(mfrow=c(2,2))
		}
	if(i/5 == round(i/5, 0)){
		dev.new()
		par(mfrow=c(2,2))
		}
	# dev.new()
	doSumPlot(levels(tData$groups)[i])
}


> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] splines   stats     graphics  grDevices utils     datasets
methods
[8] base

other attached packages:
[1] rms_3.5-0        Hmisc_3.9-3      survival_2.36-14
data.table_1.8.0

loaded via a namespace (and not attached):
[1] cluster_1.14.2 grid_2.15.0    lattice_0.20-6 tools_2.15.0



More information about the R-help mailing list