我需要使用geom_crossbar在ggplot上手动添加误差线。
我已经尝试过“ geom_arrow”,但是我找不到如何更改箭头的大小或将箭头的角度更改为90度的方法(就像我可以在图中使用功能箭头一样)。我得到的最接近的是“ geom_segment”,可以选择箭头的长度,但仍然无法更改箭头的角度。
这里是带有geom_segment的代码:
xaxis = c(5,6,7,8)
yaxis1 = c(3,3,2,1)
yaxis2 = c(6,5,3,3)
df = data.frame(cbind(xaxis,yaxis1,yaxis2))
ggplot(df) +
geom_crossbar(aes(ymin=yaxis1, ymax=yaxis2,
x=xaxis, y=yaxis1),
fill = alpha("black",0.5), fatten=0) +
geom_segment(mapping=aes(x=xaxis, y=yaxis1-0.4, xend=xaxis, yend=yaxis1+0.4),
color="black",
arrow=arrow(length = unit(0.25, "cm"), ends="both"))
任何帮助表示赞赏!