Words superimposed on the software graph R

4

Hello, I made a chart in the R, but the words were overlapping, I would like help to sort this out. Follow the graph to see how it looks. Thanks.

    
asked by anonymous 14.04.2016 / 13:49

1 answer

5

Unfortunately there is no simple solution to this. In general you have to adjust the positions manually or using some algorithm. Depending on the package you are using this possibility does not even exist, you would have to change the function of the package at hand to have that flexibility.

However, for those who use ggplot2 , a recent package that tries to position the labels without conflicts is out, named ggrepel .

See the package example.

Normal:

library(ggplot2)
ggplot(mtcars) +
  geom_point(aes(wt, mpg), color = 'red') +
  geom_text(aes(wt, mpg, label = rownames(mtcars))) +
  theme_classic(base_size = 16)

Usingggrepel:

library(ggrepel)set.seed(42)ggplot(mtcars)+geom_point(aes(wt,mpg),color='red')+geom_text_repel(aes(wt,mpg,label=rownames(mtcars)))+theme_classic(base_size=16)

The package works reasonably well, however it can choke on large databases.

    
14.04.2016 / 19:09