[R] Plot odds ratios on log scale
Marc Schwartz
marc_schwartz at me.com
Mon Dec 21 22:19:27 CET 2009
On Dec 21, 2009, at 2:54 PM, Rice, Terri wrote:
> Hi,
>
> I have the following table of odds ratios (or), lower limits(ll) and
> upper limits(ul), which I would like to plot as horizontal lines
> beginning at the lower limit, ending at the upper limits and with a
> dot at the odds ratio on an x-axis on a log10 scale. The y axis
> would be the study sites.
>
>> From what I can figure out, it looks like the plotCI function will
>> do everything except give me an x-axis that is on a log10 scale and
>> I can't get the logaxis function in the log10 package to work.
>
> Study or ll ul order
> UCSF 0.7 0.55 0.89 1
> MDA 0.76 0.71 0.93 2
> UK 0.68 0.51 0.89 3
> Mayo 0.5 0.28 0.87 4
>
> Thanks for any suggestions!
>
> Terri
Terri,
You can build your own easily, using plot() and then either arrows()
or segments() to create the CI boundary lines. Just use 'log = "x"' in
the call to plot to create the log scaled x axis.
Presuming that your data above are contained in a data frame called
'DF':
> DF
Study or ll ul order
1 UCSF 0.70 0.55 0.89 1
2 MDA 0.76 0.71 0.93 2
3 UK 0.68 0.51 0.89 3
4 Mayo 0.50 0.28 0.87 4
# Get the range of values for the x axis
xlim <- with(DF, range(or - ll, or + ul))
> xlim
[1] 0.05 1.69
# Plot the points. set the range of the x axis and set to log10 scale
plot(order ~ or, data = DF, xlim = xlim, pch = 19, log = "x")
# Add the CI's
with(DF, arrows(or - ll, order, or + ul, order, code = 3, angle = 90))
See ?arrows for help on the options for formatting the lines.
Alternatively, since it appears you are doing a meta-analysis of
sorts, you might want to look at the metaplot() and forestplot()
functions in Thomas Lumley's 'rmeta' package on CRAN.
HTH,
Marc Schwartz
More information about the R-help
mailing list