Hi, I would like to understand how does it work I mean x, y coordinates in

text() function for base R plots. So what are reference points for x and y, where does it start ?

Is it somehow connected to x and y limits ?

Is it possible to draw like a grid like lines on the plot to temporarily show how to position text annotations precisely ?

thank you

My quick test suggests that each text value is plotted with its center on the x,y coordinates.

```
X <- c(2,3,4,5)
Y <- c(23,25,27,29)
plot(X,Y)
text(X,Y,labels=c("AAAA","BBBB","CCCC","DDDD"))
```

There are arguments for adjusting this that are explained in the help file. What specific problem are you facing?

Thank you FJCC,

I try to properly position elements in forest plot from Metafor package, and this is why I would like to understand how does it work I mean x, y coordinates in text() function from base R plots, especially, because I believe they are used in Metafor package in forest() plot function.

Here below, there is a sample code:

```
library(metafor)
library(readr)
dat <- readr::read_csv("https://stat.ethz.ch/pipermail/r-sig-meta-analysis/attachments/20180730/e790230b/attachment-0001.obj")
sub <- subset(dat, outcome=="periorneomortalityany" & Parity=="nullip" & Integration=="integ")
primary <- rma(yi, vi, data=sub, measure="OR",
slab = paste(sub$author, sub$year, sep=", "),
digits=2, level=95)
forest(primary, addfit=TRUE, showweights=TRUE, atransf=exp,
xlab="Odds Ratio", mlab="Random Effects Model",
order=order(sub$PragIdeal),
ilab=cbind(sub$HomePos, sub$HomeNeg, sub$HospPos, sub$HospNeg),
ilab.xpos=c(-14.5,-12,-9,-6))
forest(primary, addfit=TRUE, showweights=TRUE, atransf=exp,
xlab="Odds Ratio", mlab="Random Effects Model",
order=order(sub$PragIdeal),
ilab=cbind(sub$HomePos, sub$HomeNeg, sub$HospPos, sub$HospNeg),
ilab.xpos=c(-20,-16,-12,-8), xlim=c(-35,20), at=log(c(.01, .1, 1, 10, 100)))
```

So my question is, where is it :

```
ilab.xpos=c(-14.5,-12,-9,-6))
ilab.xpos=c(-20,-16,-12,-8)
```

Is it related to:

```
xlim=c(-35,20)
```

Another example:

https://www.metafor-project.org/doku.php/plots:forest_plot_with_subgroups

```
### add additional column headings to the plot
text(c(-9.5,-8,-6,-4.5), 26, c("TB+", "TB-", "TB+", "TB-"))
text(c(-8.75,-5.25), 27, c("Vaccinated", "Control"))
### add text for the subgroups
text(-16, c(24,16,5), pos=4, c("Systematic Allocation",
"Random Allocation",
"Alternate Allocation"))
```

So I would like to know where is it on this plot:

```
text(c(-9.5,-8,-6,-4.5), 26,
text(-16, c(24,16,5), pos=4,
```

Please forgive me as somehow I don't see it yet.

I am not familiar with the metafor package but the positioning of the text does seem to follow the usual logic. I suggest you start with this example:

remove the ilab, ilab.xpos, and xlim arguments and plot that. Then run

```
par("usr")[1:2]
```

That will display the x axis limits used for the plot. Then run forest() again but add in the argument `xlim = c(-35,20)`

and see how the plot changes. Then add `ilab=sub$HomePos`

and ` ilab.xpos=-20`

. You can repeat the plot with ilab.pos set to -16 and see how the text column moves. I think that will help clarify how the text is placed.

I do not understand how to pick the particular ilab.xpos values other than trial and error. However, I have never used the package, so I my understanding may be completely wrong.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.