Plotting OR

## Settings for RMarkdown http://yihui.name/knitr/options#chunk_options
opts_chunk$set(comment = "", warning = FALSE, message = FALSE, echo = TRUE, 
    tidy = FALSE, fig.width = 7, fig.height = 7)
options(width = 116, scipen = 10)

Initial attempt with ggplot2

library(ggplot2)
df.data <- data.frame(OR = c(0.33,0.88,0.87),
                      LL = c(0.30,0.76,0.75),
                      UL = c(0.37,1.01,1.01),
                      name = c("Unadjusted","Adjusted for select variables","Adjusted for all covariates"))

df.data <- within(df.data, {
    summary <- paste(sprintf("%.2f",OR), " (", sprintf("%.2f",LL), "-", sprintf("%.2f",UL), ")", sep = "")

    name.and.summary <- paste(name,"  ", summary, sep = "")
})

df.data
    OR   LL   UL                          name                                name.and.summary          summary
1 0.33 0.30 0.37                    Unadjusted                    Unadjusted  0.33 (0.30-0.37) 0.33 (0.30-0.37)
2 0.88 0.76 1.01 Adjusted for select variables Adjusted for select variables  0.88 (0.76-1.01) 0.88 (0.76-1.01)
3 0.87 0.75 1.01   Adjusted for all covariates   Adjusted for all covariates  0.87 (0.75-1.01) 0.87 (0.75-1.01)

ggplot(df.data) +
    theme_bw() +
    coord_flip() +
    scale_y_continuous(breaks = c(0, 0.5, 1, 1.5, 2), limit = c(0,2)) +
    scale_x_discrete(name = "") +
    geom_pointrange(aes(y = OR, ymin = LL, ymax = UL, x = name.and.summary), lwd = 1) +
    geom_hline(y = 1)

plot of chunk unnamed-chunk-2

Modification

ggplot(df.data) +
    coord_flip() +
    opts(panel.grid.minor = theme_blank(),
         panel.grid.major = theme_blank(),
         panel.background = theme_blank(),
         axis.text.y = theme_text(size = 15, hjust = 1),
         axis.text.x = theme_text(size = 15)) +
    scale_y_continuous(breaks = c(0, 0.5, 1, 1.5, 2), limit = c(0,2)) +
    scale_x_discrete(name = "") +
    geom_pointrange(aes(y = OR, ymin = LL, ymax = UL, x = name.and.summary), lwd = 1, shape = 15) +
    geom_hline(y = 1)

plot of chunk unnamed-chunk-3

Log scale

ggplot(df.data) +
    coord_flip() +
    opts(panel.grid.minor = theme_blank(),
         panel.grid.major = theme_blank(),
         panel.background = theme_blank(),
         axis.text.y = theme_text(size = 15, hjust = 1)) +
    scale_y_log10(breaks = c(1/10, 2/10, 1/2, 1, 2/1, 10/2, 10/1), limit = c(2/10,10/2)) +
    scale_x_discrete(name = "") +
    geom_pointrange(aes(y = OR, ymin = LL, ymax = UL, x = name.and.summary), lwd = 1, shape = 15) +
    geom_hline(y = 1)

plot of chunk unnamed-chunk-4

Traditional

par(mar = c(2.1, 25, 4.1, 2.1))

plot(x = df.data$OR, y = 1:3, pch = 15,
     xaxt = "n", yaxt = "n", bty = "n",
     xlab = "", ylab = "",
     xlim = c(0,2), ylim = c(3.5, 0.5))

axis(side = 2, at = 1:3, labels = df.data$name.and.summary, las = 1, lty = 0)
axis(side = 1, at = c(0,0.5,1,1.5,2))

segments(y0 = 1:3, x0 = df.data$LL, x1 = df.data$UL, lwd = 2)

abline(v = 1)

plot of chunk unnamed-chunk-5

Traditional (log scale, axis label method)

par(mar = c(2.1, 25, 4.1, 2.1))

plot(x = df.data$OR, y = 1:3, pch = 15,
     xaxt = "n", yaxt = "n", bty = "n", log = "x",
     xlab = "", ylab = "",
     xlim = c(2/10, 2), ylim = c(3.5, 0.5))

segments(y0 = 1:3, x0 = df.data$LL, x1 = df.data$UL, lwd = 2)
abline(v = 1)
axis(side = 1, at = c(1/10, 2/10, 1/2, 1, 2/1, 10/2, 10/1), cex.axis = 1.5)

## Use axis(labels = ) for labeling
axis(side = 2, at = 1:3, labels = df.data$name.and.summary, las = 1, lty = 0, cex.axis = 1.4)

plot of chunk unnamed-chunk-6

Traditional (further modification)

par(mar = c(2.1, 25, 4.1, 2.1))

plot(x = df.data$OR, y = 1:3, pch = 15,
     xaxt = "n", yaxt = "n", bty = "n", log = "x",
     xlab = "", ylab = "",
     xlim = c(2/10, 2), ylim = c(3.5, 0.5))

segments(y0 = 1:3, x0 = df.data$LL, x1 = df.data$UL, lwd = 2)
abline(v = 1)
axis(side = 1, at = c(1/10, 2/10, 1/2, 1, 2/1, 10/2, 10/1), cex.axis = 1.5)

### Use Margin TEXT for labeling
## For names
mtext(side = 2, text = df.data$name,    at = 1:3, las = 1, adj = 0, cex = 1.5, line = 25)
## For summary statistics
mtext(side = 2, text = df.data$summary, at = 1:3, las = 1, adj = 1, cex = 1.5, line = 0)
## Labeling with bold letters
mtext(side = 2, text = c(expression(bold("Model")),expression(bold("OR (95% CI)"))), at = 0.3, las = 1, adj = c(0,1), cex = 1.5, line = c(25,0))

plot of chunk unnamed-chunk-7