[R] Plot(x,y) help

jim holtman jholtman at gmail.com
Mon Nov 26 20:23:07 CET 2012


Try this code that uses "segments" to draw in the bars

# put data into a nicer form
y=c(1.73,1.30,2.30, 1.83,1.36,2.45,1.46,1.07,2.00,1.58,1.15,2.17)
ym <- matrix(y
    , ncol = 3
    , byrow = TRUE
    , dimnames = list(NULL, c("Val", "Lower", "Upper"))
    )
ym <- cbind(ym, x = 1:4)  # add the x-coord
barWidth <- .1
# plot the data points
plot(ym[, 'x']
    , ym[, 'Val']
    , pch = 19
    , cex = 2
    , ylim = range(ym[, "Upper"], ym[, "Lower"])
    )
# draw the CI values as segments
# three sets of coords - top bar, bottom bar, connecting line
segments(c(ym[, 'x'] - barWidth, ym[, 'x'] - barWidth, ym[, 'x'])
      , c(ym[, 'Upper'], ym[, 'Lower'], ym[, 'Upper'])
      , c(ym[, 'x'] + barWidth, ym[, 'x'] + barWidth, ym[, 'x'])
      , c(ym[, 'Upper'], ym[, 'Lower'], ym[, 'Lower'])
      )



On Mon, Nov 26, 2012 at 1:31 PM, YAddo <linkyox at gmail.com> wrote:
> y=c(1.73,1.30,2.30, 1.83,1.36,2.45,1.46,1.07,2.00,1.58,1.15,2.17)



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.




More information about the R-help mailing list