[R] plotEst

hadley wickham h.wickham at gmail.com
Sat Feb 16 16:22:50 CET 2008


On Feb 16, 2008 9:11 AM, sigalit mangut-leiba <smangut at gmail.com> wrote:
> Hello,
> This is the first time i'm trying to plot in R. I want to plot estimates of
> OR and their confidence limits, like a scatter plot:
> the vertical axis should be the estimated OR (with upper and lower conf.
> limits),
>  and the horizontal exis should be fixed values: (1,0.8,0.7,0.6,0.5,0.4)
>
> Here is a part of my code:
>
> ...ests=matrix(ncol=3,nrow=6)
>
> ests[,1]<-c(mean(or1),mean(or14),mean(or15),mean(or16),mean(or17),mean(or18))
>
> ests[,2]<-c(cl1,cl14,cl15,cl16,cl17,cl18)
>
> ests[,3]<-c(cu1,cu14,cu15,cu16,cu17,cu18)
>
> x1<-c(1,0.8,0.7,0.6,0.5,0.4)...
>
> Now I have a matrix with three columns: estimate, lower limit of the
> confidende interval, and upper limit of the confidence interval:
>
>           [,1]      [,2]     [,3]
> [1,] 1.011794 0.6400744 1.383514
> [2,] 1.646535 1.0421947 2.250875
> [3,] 2.118518 1.3364878 2.900549
> [4,] 2.709806 1.6899134 3.729698
> [5,] 3.570759 2.2510895 4.890428
> [6,] 4.874569 2.9081958 6.840942
>
>
> The first value in x1 fit the first row in the matrix, etc..
>
> I tried the function plotEst like this:
>
> plotEst(ests,y = dim(ests)[1]:1, xlab="sensitivity", xtic=x1,
> xlim=range(xtic))
>
> and got the Error:
>
> Error in strsplit(x, as.character(split), as.logical(extended),
> as.logical(fixed),
> :
>         non-character argument in strsplit()
>
> What am I missing?

If you had a data.frame with columns, x, estimate, lcl and ucl, then
you could use ggplot2 as follows:

library(ggplot2)
qplot(x, estimate, min=lcl, max=ucl, data=df, geom="pointrange")

It's generally a good idea to store data in a data frame.

Hadley

-- 
http://had.co.nz/



More information about the R-help mailing list