R ggplot在误差条上放置标签

ada*_*888 2 r ggplot2

我可以创建一个带有误差线的条形图,但如何在较高的 ( vLABELH) 和较低的误差线 ( vLABELL)上放置标签。

library(ggplot2)
vx <- c(1:5)
vBAR <- c(0.1,0.2,0.3,0.4,0.5)
vLINE1 <- c(0.15,0.25,0.35,0.45,0.55)
vLINE2 <- c(0.15,0.25,0.35,0.45,0.55)
vLINE3 <- c(0.05,0.15,0.25,0.35,0.45)
vLABELL<- c(0.05,0.15,0.25,0.35,0.45)
vLABELH <- c(0.15,0.25,0.35,0.45,0.55)
df1 <- as.data.frame(cbind(vx,vBAR,vLINE1,vLINE2,vLINE3,vLABELL,vLABELH))
class(df1)
barchart1  <- ggplot(df1, aes(x=as.factor(vx),y=vBAR)) + geom_bar(fill="blue",     colour="blue")+ 
geom_errorbar(aes(ymin=vLINE3, ymax=vLINE1 ))
barchart1
Run Code Online (Sandbox Code Playgroud)

Sve*_*ein 6

我想你正在寻找geom_text.

ggplot(df1, aes(x = as.factor(vx), y = vBAR)) + 
  geom_bar(stat = "identity", fill = "blue", colour = "blue") + 
  geom_errorbar(aes(ymin = vLINE3, ymax = vLINE1 )) +
  geom_text(aes(label = vLABELH, y = vLINE1), vjust = -.5) +
  geom_text(aes(label = vLABELL, y = vLINE3), vjust = 1.5) 
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明