I'd like to set different colors for date labels on the x axis so that each month has a different color. I'm trying to use the ifelse function and I'm doing something incorrectly.
today <- Sys.Date()
tm <- seq(0, 100, by = 1)
x <- today + tm
y <- rnorm(length(x))
TD<-data.frame(date=x, value=y)
a<-ifelse(grepl("2019-12", TD$date), "red", "blue")
ggplot(data = TD, aes(x = date, y = value)) +
geom_line() +
scale_x_date(date_labels = "%d-%m-%Y", breaks = date_breaks("2 day")) +
theme(axis.text.x = element_text(angle = 45, hjust = 1, colour = a))

Aucun commentaire:
Enregistrer un commentaire