I have a small dataframe from which I am plotting 3 columns in order to display a risk estimate and the 95% confidence intervals. Right now I have those 3 sets of vectors displayed as points, but I would like to connect them using “segment”.
Here is a sample of the dataframe being plotted:
Diagnosis age.group X..change X..lower X..upper
1 Dysrythmia All adults 16 0 35
2 Heart failure All adults -4 -20 14
3 Asthma All adults 10 -5 28
Here is my plot code:
plot(dt[,4], pch="-", ylim=c(-20, 50), axes=F, ann=F, cex=1.5)
abline(h=0, col=1, lty=2)
points(dt[,3], pch=16, col="black", bg="black" )
points(dt[,5], pch="-", cex=1.5)
axis(1, at=1:10, lab=dt[,1], las=3, lwd=0, cex.axis=0.7, pos=-22)
axis(2, at=5*-20:54, las=1, cex.axis=0.7, cex.lab=0.7, col=1)
title(main="Risk estimates: All Adults", col.main="black", font.main=1)
title(ylab="Increase in risk (%)", col.lab=rgb(0,0.5,0))
box()
The points are the estimates and the dashes are the confidence intervals. I want to connect these three points for each diagnosis. I’ve looked at the R notation but it doesn’t help me figure out how to tell R which xy “coordinates” I want to draw the segments connecting, because I have used vectors here instead of values? Can anyone help write a segment line of code? Thank you
OK, so you basically want to plot CIs. The arrows command is probably better for what you want. Here’s a brief example that works with what you have for the lower CI.
You can therefore leave out the extra points commands and any new segments commands. It’s all much more concise.
But, if you insist on adding segments to what you have it’s just…