Dear All:
I would any appreciate any help with this plot I am struggling with.
I have 4 estimates (95% CIs) I want to plot. I want the CI lines to be
horizontal on each plotted point. I was trying to tweak some old codes (was
for a vertical CI lines) into horizontal but not much dice.
Many thanks in advance for your help.
YA
My working codes:
x=c(1,1,1,1.1,1.1,1.1,2,2,2,2.1,2.1,2.1)
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)
ptidx = seq(1,12,by=3)
lciidx = seq(2,12,by=3)
uciidx = seq(3,12,by=3)
plot(x,y, type="n",axes=F, xlab="PR(95% CI)",ylab="
")
points(x[ptidx],y[ptidx],pch=19,cex=4.5)
points(x[lciidx],y[lciidx],pch="_",cex=4.5)
points(x[uciidx],y[uciidx],pch="_",cex=4.5)
box()
for(i in 1:4)
{
lines(c(x[lciidx[i]],x[uciidx[i]]),c(y[lciidx[i]],y[uciidx[i]],lwd=4,cex=4.5))
}
--
View this message in context:
http://r.789695.n4.nabble.com/Plot-x-y-help-tp4650874.html
Sent from the R help mailing list archive at Nabble.com.
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.
Hello,
You had a typo in the lines() instruction, the parenthesis didn't close
after c(y...).
Anyway, I'm not sure I understand but to have horizontal lines, just
reverse the roles of x and y. (And change pch = "_" to pch =
"|").
plot(y, x, type="n",axes=F, xlab="PR(95% CI)",ylab="
")
points(y[ptidx],x[ptidx], pch=19,cex=4.5)
points(y[lciidx],x[lciidx], pch="|",cex=4.5)
points(y[uciidx],x[uciidx], pch="|",cex=4.5)
box()
for(i in 1:4){
lines(c(y[lciidx[i]], y[uciidx[i]]),
c(x[lciidx[i]], x[uciidx[i]]), lwd=4,cex=4.5)
}
Hope this helps,
Rui Barradas
Em 26-11-2012 18:31, YAddo escreveu:> Dear All:
>
> I would any appreciate any help with this plot I am struggling with.
>
> I have 4 estimates (95% CIs) I want to plot. I want the CI lines to be
> horizontal on each plotted point. I was trying to tweak some old codes
(was
> for a vertical CI lines) into horizontal but not much dice.
>
> Many thanks in advance for your help.
>
> YA
>
>
> My working codes:
>
> x=c(1,1,1,1.1,1.1,1.1,2,2,2,2.1,2.1,2.1)
> 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)
>
> ptidx = seq(1,12,by=3)
> lciidx = seq(2,12,by=3)
> uciidx = seq(3,12,by=3)
>
> plot(x,y, type="n",axes=F, xlab="PR(95%
CI)",ylab=" ")
>
> points(x[ptidx],y[ptidx],pch=19,cex=4.5)
> points(x[lciidx],y[lciidx],pch="_",cex=4.5)
> points(x[uciidx],y[uciidx],pch="_",cex=4.5)
> box()
>
> for(i in 1:4)
> {
>
>
lines(c(x[lciidx[i]],x[uciidx[i]]),c(y[lciidx[i]],y[uciidx[i]],lwd=4,cex=4.5))
>
> }
>
>
>
>
>
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/Plot-x-y-help-tp4650874.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.