R 创建GGPLOT geom_栏时geom_路径长度不兼容

R 创建GGPLOT geom_栏时geom_路径长度不兼容,r,ggplot2,R,Ggplot2,我有以下数据框和绘图代码: d <- structure(list(a = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), .Label = c("-20", "20-", "40-", "50-"), class = "factor"), tci = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L,

我有以下数据框和绘图代码:

d <- structure(list(a = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 
1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), .Label = c("-20", "20-", "40-", 
"50-"), class = "factor"), tci = structure(c(1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("A", 
"B"), class = "factor"), Score = c(1, 2, 3, 4, 5, 
6, 7, 8, 40.7, 51.9, 14.8, 3.7, 15, 75, 35, 20)), .Names = c("Foo", 
"bar", "Score"), row.names = c(NA, -16L), class = "data.frame")

library(ggplot2)
p <-ggplot(d,aes(x=Foo,y=Score,fill=bar))+geom_bar(position="dodge",stat="identity")
一种解决方案是将x和y放在数据帧中

p + geom_path(data=data.frame(x=c(0.75,0.75,1.25,1.25),y=c(42,45,45,42)),
           aes(x,y),inherit.aes=FALSE)
另一种解决方案是使用注释代替geom_路径

一种解决方案是将x和y放在数据帧中

p + geom_path(data=data.frame(x=c(0.75,0.75,1.25,1.25),y=c(42,45,45,42)),
           aes(x,y),inherit.aes=FALSE)
另一种解决方案是使用注释代替geom_路径

p + annotate(x=c(0.75,0.75,1.25,1.25),y=c(42,45,45,42),"path")