R 每个区域的连续水平几何线

R 每个区域的连续水平几何线,r,ggplot2,R,Ggplot2,对于下面ggplot中的geom_线,我希望在每个区域中都有一条绿色的直线,因为该区域中的所有维度都具有相同的值 有没有一个简单的方法可以做到这一点?我正在使用以下代码 p<- ggplot(df, aes(y=value, x=country, fill=category)) + geom_bar(stat="identity", position ="dodge")+ geom_line(aes(y=value, group = NA), col="darkgreen")+

对于下面ggplot中的geom_线,我希望在每个区域中都有一条绿色的直线,因为该区域中的所有维度都具有相同的值

有没有一个简单的方法可以做到这一点?我正在使用以下代码

p<- ggplot(df, aes(y=value, x=country, fill=category)) + 
  geom_bar(stat="identity", position ="dodge")+
  geom_line(aes(y=value, group = NA), col="darkgreen")+
  xlab("regions")+ylab("Categories")+
  theme_bw()+
  theme(legend.position = "right")+
  scale_fill_manual(" ", values = c("Ne" = "#00AFBB", "Np" = "#FC4E07", "Nt" ="#4E84C4", "Ns" ="#E7B800"))+
  theme(legend.title=element_blank())+
  theme(legend.spacing.x = unit(0.3, 'cm'))+
  scale_y_continuous(expand = c(0, 0), limits = c(0, 100),breaks = c(0,10,20,30,40,50,60,70,80,90,100))+
  scale_color_manual(name="", values = c("mean"="#3ADF00"), labels = c("Average"))

p解决方案是使用
geom_errorbar
,就像这样


为什么要将线路的组设置为NA?您是否尝试将其设置为虚拟值?为什么有两个看似相似的
geom\u line
调用?除此之外,没有两个几何图形的线很难比猜测更多,这只是一个错误,我将尝试为该线设置虚拟值。非常感谢。这基本上是一个。嗨,非常感谢你的解决方案。你可能知道如何连接水平线吗?再次感谢你!:)@很高兴它有用。不,我不知道如何连接线,但这似乎并不容易,连接线会到达一个没有任何绘制的区域。是的,尝试了我能想到的一切,但失败惨重。
library(ggplot2)

p <- ggplot(new_africa, aes(x = Africa, y = value, fill = dimension)) + 
  geom_bar(stat = "identity", position = "dodge") +
  geom_errorbar(aes(ymax = groupMeans, ymin = groupMeans, colour = mean)) +
  scale_fill_manual(values = c(GEO = "#00AFBB", 
                               NC = "#FC4E07", 
                               RE ="#4E84C4",
                               SI = "#E7B800")) +
  scale_color_manual(name = "", 
                     values = "#3ADF00", 
                     labels = "Green Growth Index") +
  xlab("Region") + ylab("Dimensions of green growth")+
  theme_bw() +
  theme(legend.position = "right",
        legend.title = element_blank(),
        legend.spacing.x = unit(0.3, 'cm'))

p
df1 <- iris
names(df1) <- c("GEO", "NC", "RE", "SI", "Africa")
df1$Africa <- c(rep("Eastern Africa", 50),
                rep("Middle Africa", 50),
                rep("Western Africa", 50))

new_africa <- reshape2::melt(df1, id.vars = "Africa")
names(new_africa)[2] <- "dimension"
new_africa$groupMeans <- ave(new_africa$value, new_africa$Africa, FUN = mean)
new_africa$mean <- "Mean"