rplotyaxisplotrixhazard

Unequal intervals on y-axis


I want to plot hazard ratios (hr) and confidence intervals from published summary data where I have the respective publication on the x-axis and the hazard ratios on the y-axis.

Currently, my y-axis reads: (-3, -2, -1, 0, 1, 2, 3), which gives an "unsymmetrical" scaling of the hrs.

Plot of HRs

How do I program the y-axis to read: (0.3, 0.2, 0.1, 0, 1, 2, 3), which will give a "correct" scaling of the hrs?

#require(plotrix)

#Create a data frame containing hr and confidence intervals 
mean <-       c(0.73, 0.7, 0.6, 0.74, 0.9, 0.96, 0.87, 0.74)
lowerlimit <- c(0.1, 0.4, 0.34, 0.29, 0.79, 0.86, 0.72, 0.57)
upperlimit <- c(5.55, 1.16, 0.99, 1.85, 1.03, 1.17, 1.04, 1.12)
df <- data.frame(cbind(upperlimit,lowerlimit, mean))

#Create a plot of the hr and CI for the respective publications
plot(df$mean, ylim = c(-3, 3), xlim = c(1,8), xaxt="n")

axis(1, at=seq(1:8), las=2,
 labels=c("study1", "study2", "study3", "study4", "study5", "study6", "study7", "study8"))

plotCI(df$mean, y=NULL, uiw=df$upperlimit, liw=df$lowerlimit, err="y", pch=20, slty=3, scol = "blue", add=TRUE)

Ps. If amending the interval is not possible, then there is an intermediate step where (1/lowerlimit) will give the right scaling but the "wrong number". Then, hard coding the y-axis could prove to be a solution (have attempted this without success).


Solution

  • There might be several ways to do this. Here is my ggplot approach. You could dress it up accordingly.

    Your data

    mean <-       c(0.73, 0.7, 0.6, 0.74, 0.9, 0.96, 0.87, 0.74)
    lowerlimit <- c(0.1, 0.4, 0.34, 0.29, 0.79, 0.86, 0.72, 0.57)
    upperlimit <- c(5.55, 1.16, 0.99, 1.85, 1.03, 1.17, 1.04, 1.12)
    study <- c(1:8)
    df <- data.frame(cbind(upperlimit,lowerlimit, mean, study))
    

    My ggplot approach:

    library(ggplot2)
    labels <- paste("Study", c(1:8))
    df %>% 
    ggplot(aes(x = study, y= mean)) + 
      geom_point() + 
      geom_errorbar(aes(ymin = lowerlimit, ymax = upperlimit), width = 0.1) + 
      scale_y_log10() + 
      scale_x_continuous(breaks = c(1:8), labels = labels)
    

    You get: enter image description here