Using lubridate and ggplot2 effectively for date axis
问题 Consider this example: library(ggplot2) library(lubridate) set.seed(4) date <- seq(from = as.POSIXct("2012-01-01"), to = as.POSIXct("2014-12-31"), by = "days") value <- c(rnorm(274, 50, 1), rnorm(274, 55, 1), rnorm(274, 55, 2), rnorm(274, 60, 2)) df <- data.frame(date, value) head(df) # date value # 1 2012-01-01 50.21675 # 2 2012-01-02 49.45751 # 3 2012-01-03 50.89114 # 4 2012-01-04 50.59598 # 5 2012-01-05 51.63562 # 6 2012-01-06 50.68928 ggplot(df, aes(x=yday(date), y=value, color=factor