Salah Uddin
Salah Uddin

Reputation: 25

How can I add an annotation like this?

enter image description here

How can I add annotation in ggplot like this? I need to add the text (CV, Network), the bars, and also those stars.

Upvotes: 0

Views: 89

Answers (1)

Julian_Hn
Julian_Hn

Reputation: 2141

I hope you can transfer this example to your dataset:

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

enter image description here

Upvotes: 4

Related Questions