[R] how to add point and label to boxplot using bwplot

Maria Montez montez at bu.edu
Fri Jun 2 01:09:01 CEST 2006


Hi.

My data contains information for 10 hospitals for 12 different measures.
Let's call it x1-x12. I need to create a boxplot for each one of this
measures and put them into one page. Each plot also needs to be independent,
i.e. cannot use the group feature because of different scales for each
measure. I was successful using the following code:

x1 <- c(1.317604376, 0.978038233, 0.396823901, 0.601130135, 1.039993474,
0.434282156, 0.941604514, 0.84796521, 1.614475852, 2.723760844)
c1 <- as.integer(c(9, 9, 2, 7, 10, 1, 11, 49, 26, 5))

plot1 <- bwplot(x1,cex=.5,scales=list(cex=0.5), xlab=list("psi03",cex=.5))
print(plot1,split=c(1,1,1,12),more=TRUE)

#plot2<-bwplot(x2,cex=.5,scales=list(cex=0.5), xlab=list("psi04",cex=.5))
#print(plot2,split=c(1,2,1,12),more=TRUE)

... (code for other 10 plots)

The main purpose is to create one of this pages with information relative to
each hospital. So, on each boxplot I need to add a point indicating where
that hospital falls with a label that indicates the number of cases
regarding that variable. Then I create 10 different pages.

I first tried this without using lattice plots by doing:

boxplot(x1, horizontal=TRUE)
points(x1[4],1,pch=19) #plot point for hospital 2
text(x1[4],0.95,c1[4]) # next to that point indicate number of cases

How can I do the same in a lattice plot? I've tried the following, but it
doesn't work (I think I might not be passing the right arguments):

bwplot(x1,cex=.5,scales=list(cex=0.5),tck=0.5, xlab=list("psi03",cex=.5),
			panel=function(x,c1){
					panel.bwplot(x)
					panel.points(x[2],0.5,pch=19)
					panel.text(x[4],0.95,c1[4])
				}
	)

Many thanks, Maria



**********************************************************
Maria E Montez
Programmer / Data Analyst
Center for Health Quality, Outcomes and Economic Research
VA Medical Center
Bedford, MA



More information about the R-help mailing list