0

I need to wrap the text in this plot. Anyone knows how?

I already tried using check_overlap but the labels are very separated from each other.

    ex<-data.frame(x=1:10, y=c(1.732050808, 1.732050808, 1.732050808, 1.732050808, 0.866025404, 0.866025404, 0.866025404, 0.866025404, 0.866025404, 0.866025404
), z="Very very very very very very very very very very long text")

ggplot(ex,mapping = aes(x,y, label = (z)))+
  geom_text(size=2, check_overlap = F)+
  geom_point()

enter image description here

sebastian-montero
  • 379
  • 1
  • 4
  • 18

1 Answers1

0

You could use the ggrepel package to avoid overlapping issues. You just need to replace geom_text by geom_text_repel and remove the argument check_overlap. For instance:

library(ggrepel)
ggplot(ex,mapping = aes(x,y, label = (z)))+
  geom_text_repel(size=2)+
  geom_point()

Output: enter image description here

Edgar Santos
  • 3,426
  • 2
  • 17
  • 29
  • Hi! Actually I did try it but it didn't work given the amount of points (example above) – sebastian-montero Apr 27 '17 at 23:41
  • you could play around the font size, orientation and segment.size, etc. If the number of data points is huge you won't be able of accommodating them in the plot. For that case, there is not much point adding the text to the plot. You could use ggplotly that displays info of the dot hovering over a data point – Edgar Santos Apr 27 '17 at 23:47