0

I have points on the map that are very close to each other and I would like to separate the labels because they are overlapping. I want to use spread.labels command, but I get an error smth along this line:

Error in text.default(newx, y + offsets, labels[sort.index], srt = srt,  : plot.new has not been called yet  

  mp = get_map(location = "Canada", maptype="satellite", color="color")
p = ggmap(mp) +
  geom_point(data=df1, aes(x=decLon, y = decLat), color="red", size=2.6) +
  spread.labels(x=df1$decLon, y=df1$decLat, label=df1$Site, offsets=0.5)
p   
Prophet
  • 32,350
  • 22
  • 54
  • 79
yuliaUU
  • 1,581
  • 2
  • 12
  • 33
  • You looks like you are mixing base and grid plot (ggplot2). I think you should use something like `directlables` package. – agstudy Jun 09 '14 at 20:17
  • The `spread.labs` function in TeachingDemos: http://finzi.psych.upenn.edu/R/library/TeachingDemos/html/spread.labs.html will return coordinates that you could use in a ggplot2 labeling or annotation function. – IRTFM Jun 09 '14 at 20:54
  • thanks for teh help! I used TkIdentify, works pretty well – yuliaUU Jun 10 '14 at 01:28

1 Answers1

1

there are separate package for ggplot2, it's called ggrepel, can solve the problem

rankthefirst
  • 1,370
  • 2
  • 14
  • 26