Morts81
Morts81

Reputation: 439

Metafor Package (R) - Adding Multiple Columns

I've currently got a data frame as per below called final

final
     Gms AvgPts   max   min   Team salary position playing.status value                         Players
    (dbl)  (dbl) (dbl) (dbl) (fctr)  (dbl)   (fctr)         (fctr) (dbl)                           (chr)
1      2  87.00   113    61    STK   4300      FWD          Start 20.23     Tim Membrey, STK, FWD, 4300
2      4  75.50   124    42    STK   4300      MID          Start 17.56     Blake Acres, STK, MID, 4300
3      7  77.43   119    50    STK   5500       RU          Start 14.08       Tom Hickey, STK, RU, 5500
4      6  87.00   110    54    WCE   6200       RU    Interchange 14.03     Scott Lycett, WCE, RU, 6200
5      5  71.40    89    39    STK   5200      FWD    Interchange 13.73   Jack Sinclair, STK, FWD, 5200
6      3  73.33    83    68    WCE   5400      MID          Start 13.58  Mark Hutchings, WCE, MID, 5400
7      7  98.71   127    83    STK   7400      MID    Interchange 13.34  Sebastian Ross, STK, MID, 7400
8      7  79.14    99    53    WCE   6100      DEF          Start 12.97 Jeremy McGovern, WCE, DEF, 6100
9      7 108.29   198    67    WCE   8500      FWD          Start 12.74 Josh J. Kennedy, WCE, FWD, 8500
10     6 121.00   150    57    STK   9500      FWD          Start 12.74   Nick Riewoldt, STK, FWD, 9500
11     6  79.17   101    59    STK   6400      MID          Start 12.37    Luke Dunstan, STK, MID, 6400
12     7  84.86   104    60    STK   7000      DEF          Start 12.12    Shane Savage, STK, DEF, 7000
13     7  82.14   100    45    WCE   6900      FWD          Start 11.90    Jack Darling, WCE, FWD, 6900
14     7  95.29   138    76    WCE   8100       RU          Start 11.76     Nic Naitanui, WCE, RU, 8100
15     7  87.43   135    53    WCE   7500      FWD          Start 11.66     Mark LeCras, WCE, FWD, 7500
16     7  74.29    92    34    WCE   6400      DEF          Start 11.61   Brad Sheppard, WCE, DEF, 6400

I use the following lines of code to produce a forest plot as shown below:

forest(x = final$AvgPts, ci.lb = final$min, ci.ub = final$max, slab = final$Players,ilab = final$value, ilab.xpos = max(final$max)+10,ilab.pos =4,yaxs="i", alim = c(min(final$min)-5, max(final$max)+5),steps = 4, xlim = c(min(final$min)-200, 2*(max(final$max)+5)), xlab = "Moneyball Points Spread", efac = 0.75-.0014*k, cex = 0.75, mgp = c(1, 1, 0),refline=mean(final$AvgPts),digits=1,col="dark blue",pch = 19,main=paste("2016 Moneyball Summary - pos =",paste(as.character(pos), collapse=", "),"\n(avg >=",points,"-- value >=",val,"-- TOG >=",time,")"))

text(min(final$min)-200, (nrow(final) + 1.5), "Player",pos=4,cex=0.75)
text(max(final$max)+10, (nrow(final) + 1.5), "Value",pos=4,cex=0.75)
text(2*(max(final$max)+5), (nrow(final) + 1.5), "Average[min,max]",pos=2,cex=0.75)

enter image description here

What I want to be able to do is add more columns than just the Value column (ilab = final$value).

Ideally I would like a solution which would be able to fit more than just one additional column as I intend to build on the final data frame with more information.

Also, is it possible to add extra columns before AND after the plot line section?

Upvotes: 1

Views: 1106

Answers (1)

Wolfgang
Wolfgang

Reputation: 3395

The ilab argument can also take an entire matrix or data frame (and ilab.pos and ilab.xpos should then be vectors). See help(forest.rma) for examples. And yes, if you adjust xlim so there is sufficient space to the left and the right of the points and CI lines, you can place the information to the left and right as well (just use ilab.xpos to specify where you want the various columns placed).

Upvotes: 1

Related Questions