答案 0 :(得分:4)
我希望您可以将此示例转移到您的数据集中:
ggplot() + geom_point(aes(x = 1:10, y = 1:10)) +
geom_segment(aes(x=0,y=11,xend=5,yend=11)) + geom_segment(aes(x=0,y=11,xend=0,yend=10.5)) + geom_segment(aes(x=5,y=11,xend=5,yend=10.5)) + ##bracket 1
geom_segment(aes(x=5.5,y=11,xend=10,yend=11)) + geom_segment(aes(x=5.5,y=11,xend=5.5,yend=10.5)) + geom_segment(aes(x=10,y=11,xend=10,yend=10.5)) + #bracket 2
geom_text(aes(x=2.5,y=11.5,label="Group 1")) + geom_text(aes(x=7.75,y=11.5,label="Group 2")) + #add labels
coord_cartesian(ylim = c(0, 10), clip="off")+theme(plot.margin = unit(c(4,1,1,0), "lines")) #change plot margins