在 geom_rect 背景上绘制 geom_segment

Plot geom_segment on geom_rect background

我想在 geom_rect 上用深绿色填充绘制线段(准确地说:geom_segment 元素)。

我使用以下代码:

ggplot(data, aes(x=X0, y=Y0, xend=X1, yend=Y1))+
  geom_segment(aes(colour=Result)) + 
  scale_colour_manual(values=c("green", "red"))+
  theme(panel.background = element_rect(), 
        panel.grid.major = element_line( colour = "white") )+
  scale_y_continuous(breaks=seq(20,100, by=5))+
  geom_rect(aes(xmin = 0, xmax = 100, ymin = 62, ymax = 100), 
            fill = "grey") +
  geom_rect(aes(xmin = 0, xmax = 100, ymin = 60, ymax = 62), 
            fill = "darkgreen")+ 
  geom_rect(aes(xmin = 0 , xmax = 100, ymin = 50, ymax = 60), 
            fill = "darkgreen", colour = "white", size = 1)+
  geom_rect(aes(xmin = 50, xmax = 50, ymin = 60, ymax = 65), 
            fill = "yellow", colour = "yellow", size = 4)

...等等。

这给了我:

我认为列出的顺序就是绘制的顺序,所以将 geom_segment 放在最后应该可以。