Home > Blockchain >  ggplot2: Repel text using same x coordination
ggplot2: Repel text using same x coordination

Time:03-13

I'am trying use geom_text_repel and geom_point to repel all text but its only works witch same column (red repel with red, blue with blue but red won't repel with blue). Both columns use same x coordinate so I don't have idea how do this. There is sample code and effect:

data <-  data.frame(c(NA,NA,2.10,3.30,10,NA,3,NA,NA,0.80),c(4,NA,2,3.50,NA,NA,NA,NA,NA,1))
text <- c("text1","text2","text3","text4","text5","text6","text7","text8","text9","text10")
colnames(data) <- (c("data1","data2"))
ggplot(data,aes(x=seq(1,10), y=data))   geom_point(color = "red",aes(y=data1))   geom_point(aes(y=data2), color = 'blue')   
geom_text_repel(aes(seq(1,10),data1, label = text))   geom_text_repel(aes(seq(1,10),data2, label = text))

enter image description here

  • Related