Combine two columns in one row in the title of a forestplot in R

562 views Asked by At

I have a forest plot and I'm trying to combine two columns in an only row for a title.

My database is like this:

> text.TI[1:10,]
              Names   Present         Absent            OR                     
         [1,] ""      ""              ""                ""                     
         [2,] "Drug"  "Drug Present"  "Drug Absent"     "aOR (95%CI)"          
         [3,] ""      ""              ""                ""                     
         [4,] ""      ""              ""                ""                     
         [5,] "N03AG" "3/5 (60.0%)"   "179/973 (18.4%)" "60.52 (6.02 - 608.82)"
         [6,] "A10AB" "6/8 (75.0%)"   "176/970 (18.1%)" "14.40 (2.16 - 95.89)" 
         [7,] "J01EA" "12/24 (50.0%)" "170/954 (17.8%)" "8.43 (3.23 - 22.00)"  
         [8,] "A07AA" "3/5 (60.0%)"   "179/973 (18.4%)" "7.22 (1.01 - 51.74)"  
         [9,] "B01AB" "6/12 (50.0%)"  "176/966 (18.2%)" "5.61 (1.45 - 21.71)"  
         [10,] "B03XA" "5/9 (55.6%)"   "177/969 (18.3%)" "5.37 (1.18 - 24.47)"  

> m.TI[1:10]
 [1]       NA       NA       NA       NA 4.103040 2.667506 2.131678 1.977270 1.725263 1.681573
> l.TI[1:10]
 [1]         NA         NA         NA         NA 1.79458880 0.77195836 1.17248214 0.00796817 0.37225297 0.16636154
> u.TI[1:10]
 [1]       NA       NA       NA       NA 6.411518 4.563254 3.090952 3.946173 3.077957 3.197284
    

when I do my forestplot with this code:

  tiff('HR1.tiff', units="in", width=10, height=20, res=300)
    forestplot(text.TI,m.TI,l.TI,u.TI,xlog=T,zero=0,
     is.summary=c(T,T,T,T,rep(F,87)),
     col = meta.colors(lines="black",zero="black"),    align=c('l','c'),clip=c(log(0.1),log(20)),boxsize=c(rep(0.4,91)),graphwidth=unit(4, "inches"))
        x <- unit(.451, 'npc')
    y <- unit(.15, 'npc')
    x2 <- unit(.29, 'npc')
    y2 <- unit(.11, 'npc')
    xt <- unit(.5, 'npc')
    yt <- unit(.84, 'npc')

I obtain my forest plot

enter image description here

My objective is to actually have a text that is in two cells combining two columns, that I'm actually doing it with an image editor after doing my forestplot:

enter image description here

See that the text "no. of patients who died/total no.%" is actually in row 2 and 3 together.

Is there any way of doing this directly in R and obtain that image as the output of my forestplot function, and not using an image editor?

1

There are 1 answers

0
J Louro On BEST ANSWER

I solved it using the function grid.text

with this code:

grid.text("no. of patiens who died/total no. (%)", .5, .9, gp = gpar(fontsize=10, font = 3))