'ggplot with overlapping X axis label
I have a ggplot which looks like this.
p2=ggplot(data=data1, aes(x=ID, y = value)) +
geom_line(group=1,color='steelblue', size=2) + facet_wrap(~variable)+theme_economist()
p2=p2+theme(text = element_text(size=10), axis.text.x = element_text(angle=90, hjust=1))
p2
The issue is that, I am getting overlapping X labels in the X axis. Is there any way to get non overlapping X axis labels.
Solution 1:[1]
There is nice solution to this problem with ggplot2 version 3.3.0.
scale_x_discrete(guide = guide_axis(n.dodge=3))
Here is an example
Solution 2:[2]
Try + coord_flip()
-- the labels might fit better and be more legible on the y-axis.
Solution 3:[3]
How about?
theme(axis.text.x = element_text(angle =45, hjust = 1))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Anoushiravan R |
Solution 2 | jtr13 |
Solution 3 | Jeremy Caney |