Skip to content
Prev 217675 / 398500 Next

plotting RR, 95% CI as table and figure in same plot

Hi all--

I am in the process of helping colleagues write up a ms in which we fit 
zero-inflated Poisson models.  I would prefer plotting the rate ratios 
and 95% CI (as I've found Gelman and others convincing about plotting 
tables...), but our journals usually like the numbers themselves.

Thus, I'm looking at a recent JAMA article in which both numbers and 
dotplot of RR and 95% CI are presented and wondering about best way to 
do this in R.

Essentially, the plot has 3 columns: variable names, RR and 95% CI, and 
dotplot of the same.

Using the bioChemists data in the pscl package and errbar function in 
Hmisc package, the code below is in the right direction... but still 
pretty ugly.

Wondering if folks would have alternative suggestions about how to go 
about this, or pointers on cleaning up the code below (eg, I know there 
are many functions for plotting errbars/CI).

[And, obviously, there are somethings that would be straightforward to 
clean-up such as supplying better variable names, etc., just wanted to 
see if there were better overall suggestions before getting too far on 
this route.]

Thanks in advance.

cheers, Dave

library(Hmisc)
library(pscl)	

## data
data("bioChemists", package = "pscl")
fm_pois <- glm(art ~ ., data = bioChemists, family = poisson)
summary(fm_pois)

### pull out rate-ratios and 95% CI
rr <- exp(cbind(coef(fm_pois), confint(fm_pois)))
rr
### round to 2 decimal places
rr <- round(rr, 2)

### plot
par(mfrow=c(1,3))
plot(0, type = "n", xlim=c(0,2), ylim=c(1,6),
	axes = FALSE, ylab=NULL, xlab=NULL)
text(row.names(rr), x = 1, y = 1:6)

plot(0, type = "n", xlim=c(0,2), ylim=c(1,6),
	axes = FALSE, ylab=NULL, xlab=NULL)
text(paste(rr[,1], " [", rr[,2], ", ", rr[,3], "]", sep = ""), x = 1, y 
= 1:6)

errbar(x = factor(row.names(rr)),
		y = rr[,1], yplus = rr[,3],
		yminus = rr[,2])
abline(v = 1, lty =2)