0

I am using the geom_label_repel function to arrange labels in a way that avoids overlapping but when I add an regression line to my plot, then it itself overlaps the labels.

ggplot(globalMetrics, aes(x=globalMetrics$popDensity, y=globalMetrics$turnover)) + geom_point() +
  theme_bw() +  geom_label_repel(aes(label= rownames(globalMetrics)), size=3) + stat_smooth(method="lm")

Is there a way to avoid this in ggplot?

enter image description here

Here is a sample of the data:

 dput(globalMetrics)
structure(list(popDensity = c(4308, 27812, 4447, 5334, 4662, 
2890), turnover = c(2.65, 4.49, 2.37, 2.87, 3.87, 2.95)), .Names = c("popDensity", 
"turnover"), row.names = c("label1", "label2", "label3", "label4", 
"label5", "label6"), class = "data.frame")
iskandarblue
  • 7,208
  • 15
  • 60
  • 130
  • If you put the `stat_smooth` before the `geom_label_repel` then the labels appear on top of the line with a white background, which is an improvement – Andrew Gustar Apr 19 '17 at 15:11
  • I believe there is not a good way to dodge across `ggplot` layers. Thus, I don't know if its possible to get what you want without some manual changes. – Mike H. Apr 19 '17 at 15:19

0 Answers0