Average graph of a diamond on a box in R
1 answer
It is easy to write a function like the following. Enter x and y for mean, upper limit, lower limit, and diamond width. You can pass other parameters like lty for linetype and col color to segments.
diamondCI <- function(x, y, ul, ll, w = ul-ll, ...){
hw <- w/2
segments(x-hw, y, x+hw, y, ...) # horizontal bar
segments(x-hw, y, x, ul, ...) # left upper diag
segments(x, ul, x+hw, y, ...) # right upper diag
segments(x-hw, y, x, ll, ...) # left lower diag
segments(x, ll, x+hw, y, ...) # right lwoer diag
}
Try with ...
plot(1,1)
diamondCI(1, 1, 1.2, 0.7, col = 'red', lwd = 3)
+3
source to share