[R] Plot odds ratios on log scale
(Ted Harding)
Ted.Harding at manchester.ac.uk
Mon Dec 21 23:13:42 CET 2009
On 21-Dec-09 21:19:27, Marc Schwartz wrote:
> 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
While Marc was posting the above, I was working out an example
on just those lines! It is simply an illustration of how one
can proceed. Often, it is worth while constructing one's plot
"by hand", since then you can cook things exactly as you want
them (Haute Cuisine), rather than get served with what's been
prepared (Pizza Bar, even if it is a high-quality one).
Here is ths code:
## Construct the dataframe
X<-rbind(
c(0.7,0.55,0.89,1),
c(0.76,0.71,0.93,2),
c(0.68,0.51,0.89,3),
c(0.5,0.28,0.87,4)
)
colnames(X)<-c("OR","LL","UL","Order")
rownames(X)<-c("UCSF","MDA","UK","Mayo")
Xdf<-as.data.frame(X)
## Construct the plot
plot(Xdf$OR, (5-Xdf$Order), pch=20, log="x",
xlim=c(0.2,1), ylim=c(0.5,4.5),
axes=FALSE, frame.plot=TRUE,
xlab="OR with Confidence Limits", ylab="Order")
at.x <- 0.2*(1:5)
axis(1,at=at.x,labels=formatC(at.x,format="fg"))
for(i in (1:4)){
y <- (5-Xdf$Order[i])
lines(c(Xdf$LL[i],Xdf$UL[i]),c(y,y))
text(0.2,i,labels=as.character(y),pos=4)
text(0.21,y,labels=rownames(Xdf)[i],pos=4)
}
## Especially see ?plot and ?plot.default for details
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 21-Dec-09 Time: 22:13:40
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list