-2

I want to ask about the ggplot2
Datasets

Date is classified as the "date format". However, when I tried to draw timeseries from ggplot it shows strange x axis.

ggplot()+ 
    geom_line(data = Farm.MLR, aes(x = date, y = observed), colour = "black")+ 
    scale_x_date(labels = function(x) format(x, "%d-%b-%y"))+ 
    geom_point(data = Farm.MLR, aes(x = date, y = observed), colour = "black")+ 
    xlab("Date") + ylab("SM")

Result

Do you have any idea what's problem with my code?

J.Con
  • 4,101
  • 4
  • 36
  • 64
Aiden Park
  • 1
  • 1
  • 2

1 Answers1

3

Formatting function is not correct, should be

 scale_x_date(date_labels= "%d-%b-%y"))

instead of

scale_x_date(labels = function(x) format(x, "%d-%b-%y"))
Erdem Akkas
  • 2,062
  • 10
  • 15
  • And use date_breaks to control the distance between axis breaks (e.g., scale_x_date(date_labels = "%d-%b-%y", date_breaks = "1 month"). – Peter K May 13 '17 at 05:58