Panchacookie
Panchacookie

Reputation: 427

ggplot with overlapping X axis label

I have a ggplot which looks like this.enter image description here

 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.

Upvotes: 4

Views: 19219

Answers (4)

Chryzl
Chryzl

Reputation: 181

This will remove all labels which overlap:

scale_x_discrete(guide = guide_axis(check.overlap = TRUE))

Upvotes: 0

DataVizPyR
DataVizPyR

Reputation: 129

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

Upvotes: 7

Min
Min

Reputation: 179

How about?

theme(axis.text.x = element_text(angle =45, hjust = 1))

Upvotes: 2

jtr13
jtr13

Reputation: 1277

Try + coord_flip() -- the labels might fit better and be more legible on the y-axis.

Upvotes: 2

Related Questions