Meso
Meso

Reputation: 1435

How to produce multiple horizontal error bars as shown in the link

I am interested to produce a plot similar to figure two published in JAMA article found here. I would appreciate any suggestion on how to produce similar figure in R. Sample data is found on this link https://drive.google.com/file/d/0B_4NdfcEvU7LUXB4TW9jWWZPODA/edit?usp=sharing.

enter image description here

Thanks

Upvotes: 0

Views: 363

Answers (1)

MrFlick
MrFlick

Reputation: 206197

The sample data is extremely helpful. Thank you.

The simplest ggplot code would probably be

ggplot(df, aes(x=est, y=interaction(pollut, lag, lex.order=TRUE))) + 
    geom_point() + 
    geom_errorbarh(aes(xmin=lcl, xmax=ucl)) + geom_vline(x=0)

which gives

enter image description here

You could start customizing with

ggplot(df, aes(x=est, y=lag)) + 
    geom_point() + 
    geom_errorbarh(aes(xmin=lcl, xmax=ucl)) + geom_vline(x=0) + 
    facet_grid(pollut~.) + 
    theme(panel.background=element_rect(fill="white"))

enter image description here

Upvotes: 2

Related Questions