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.
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.