Dear R Users: I have the individual mortality rate and 95% CI of 100 hospitals, how to do the plot with the individual hospital in the Yaxis, and the mortality rate and 95% CI in the Xais and a overall mean as a reference line? Thanks and regards, Xin [[alternative HTML version deleted]]
XINLI LI <lihawaii <at> gmail.com> writes:> > Dear R Users: > > I have the individual mortality rate and 95% CI of 100 hospitals, > how to do the plot with the individual hospital in the Yaxis, and the > mortality rate and 95% CI in the Xais and a overall mean as a reference > line?Something like library(plotrix) plotCI(mortratevec,1:n,li=mort.lo,ui=mort.hi,err="x",axes=FALSE) axis(side=1) axis(side=2,at=1:n,label=hospitalnames,padj=0,las=1) box() abline(v=meanmort) ggplot2 is another option: more complicated to get working, but very pretty. You'll want to look at geom_point geom_linerange coord_flip geom_hline
Hi: Following up on Ben's suggestion re ggplot2, here's a manufactured example: # Fake data: mortrate <- round(runif(100), 3) dd <- data.frame(rate = mortrate, moe = 1.96 * sqrt(mortrate * (1 - mortrate))/10, hosp = factor(paste('H', 1:100, sep = ''))) dim(dd) [1] 100 3 # Set up the plot: ymin and ymax are input parameters to geom_pointrange g <- ggplot(dd, aes(x = hosp, y = rate, ymin = rate - moe, ymax = rate + moe)) # Version with hospitals in lexicographic order (rather useless): g + geom_pointrange() + geom_hline(aes(yintercept = mean(rate))) + scale_x_discrete(expand = c(0.01, 0.01)) + coord_flip() + theme_bw() + opts(axis.text.y = theme_text(size = 5, hjust = 1)) # Version with hospitals sorted by rate (better): g + geom_pointrange(aes(x = reorder(hosp, rate, mean))) + geom_hline(aes(yintercept = mean(rate))) + scale_x_discrete(expand = c(0.01, 0.01)) + coord_flip() + theme_bw() + opts(axis.text.y = theme_text(size = 5, hjust = 1)) Hope you like it... Dennis On Tue, Oct 19, 2010 at 4:59 PM, XINLI LI <lihawaii@gmail.com> wrote:> Dear R Users: > > I have the individual mortality rate and 95% CI of 100 hospitals, > how to do the plot with the individual hospital in the Yaxis, and the > mortality rate and 95% CI in the Xais and a overall mean as a reference > line? > > Thanks and regards, > > Xin > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
You could also use lattice + Hmisc: # Fake data (taken from Dennis Murphy's reply): mortrate <- round(runif(100), 3) moe = 1.96 * sqrt(mortrate * (1 - mortrate))/10 dd <- data.frame(rate = mortrate, CI.lower = mortrate - moe, CI.upper = mortrate + moe, hosp = factor(paste('H', 1:100, sep = ''))) # using packages lattice and Hmisc: require(lattice) require(Hmisc) dd$hosp.sort <- reorder(dd$hosp, dd$rate) Dotplot(hosp.sort ~ Cbind(mortrate, CI.lower, CI.upper), data = dd, abline = list(v = mean(mortrate), col = "red")) HTH Heinrich.> -----Urspr?ngliche Nachricht----- > Von: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] Im Auftrag von XINLI LI > Gesendet: Mittwoch, 20. Oktober 2010 02:00 > An: R-help at r-project.org > Betreff: [R] plot CI and mortality rate > > > Dear R Users: > > I have the individual mortality rate and 95% CI of 100 > hospitals, > how to do the plot with the individual hospital in the > Yaxis, and the > mortality rate and 95% CI in the Xais and a overall mean as a > reference > line? > > Thanks and regards, > > Xin > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide > commented, minimal, self-contained, reproducible code. >