-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
I get an error with when plotting confidence intervals with larrows in a plot with a grouping variable (but it works with lsegments).
newdat <- read.table(text="
age Sex distance pvar1 tvar1 thi tlo
8 Female 21.20909 0.4030807 6.177568 33.31712 9.101058
10 Female 22.16818 0.3418827 6.116370 34.15627 10.180096
12 Female 23.12727 0.3667087 6.141196 35.16402 11.090529
14 Female 24.08636 0.4775585 6.252046 36.34037 11.832354
8 Male 22.61563 0.2771180 6.051605 34.47677 10.754479
10 Male 24.18438 0.2350444 6.009532 35.96306 12.405693
12 Male 25.75312 0.2521122 6.026600 37.56526 13.940990
14 Male 27.32187 0.3283215 6.102809 39.28338 15.360370
", header=TRUE)
I get the desired plot when the vertical bars are drawn with panel.segments:
xyplot(distance ~ age, group= Sex, data=newdat, ylim=c(0,50),
panel = panel.superpose.2, col=c("red","blue"),
panel.groups = function (x,y, lx, ux, subscripts, group.value, ...){
x <- if(group.value=="Male") x - 0.1 else x + 0.1
panel.xyplot(x,y,...)
panel.segments(x0 = x, y0 = lx[subscripts], x1 = x, y1 = ux[subscripts], ...)
# panel.arrows(x0 = x, y0 = lx[subscripts], x1 = x, y1 = ux[subscripts], ...)
},
lx=newdat$tlo, ux=newdat$thi
)
but not with panel.arrows:
xyplot(distance ~ age, group= Sex, data=newdat, ylim=c(0,50),
panel = panel.superpose.2, col=c("red","blue"),
panel.groups = function (x,y, lx, ux, subscripts, group.value, ...){
x <- if(group.value=="Male") x - 0.1 else x + 0.1
panel.xyplot(x,y,...)
# panel.segments(x0 = x, y0 = lx[subscripts], x1 = x, y1 = ux[subscripts], ...)
panel.arrows(x0 = x, y0 = lx[subscripts], x1 = x, y1 = ux[subscripts], ...)
},
lx=newdat$tlo, ux=newdat$thi
)
=> Errors using packet 1: invalid 'ends' or 'type' argument
I have tried to specify arrows arguments (ends, length, angle) but it does not help. Note that the function larrows works in the panel function:
xyplot(distance ~ age | Sex, data=newdat, ylim=c(0,50),
panel = function (x,y, lx, ux, subscripts, ...) {
panel.xyplot(x,y,...)
panel.arrows(x0 = x, y0 = lx[subscripts], x1 = x, y1 = ux[subscripts],
ends="both", length=0.1, angle=90, ...)
},
lx=newdat$tlo, ux=newdat$thi
)
Session info: R version 4.3.1, lattice_0.21-8
Metadata
Metadata
Assignees
Labels
No labels

