useR
useR

Reputation: 3082

adjust x-axis label scale in ggplot2

I would like to make a ggplot graph with Period on the x-axis like 2010-01, 2010-02 ..., 2014-03

And my code are like followings:

 ggplot(Result, aes(x=factor(Period), y=No_Seats, colour=Airline, group=Airline)) + geom_line()

And the graph is like this: enter image description here

As you can see we can see the period label clearly. I like to make the period a vertical label. Thanks!

Upvotes: 1

Views: 667

Answers (2)

ThinkStatsme
ThinkStatsme

Reputation: 1

You could use the scales library and provided x-axis is a date you can use something like

scale_x_date(breaks=Dbreaks,labels=date_format("%Y"))

Where Dbreaks is your specified breaks (most be date breaks otherwise it won't work) and format how you would want it to be printed. With the same library you can specify your breaks. For example

Dbreaks <- seq(as.Date("2006-06-01"),as.Date("2013-06-1"),by='1 year').

Upvotes: 0

David Arenburg
David Arenburg

Reputation: 92300

add

+ theme(axis.text.x =  element_text(angle=90))

Upvotes: 3

Related Questions