【发布时间】:2019-07-09 00:45:38
【问题描述】:
我正在尝试使用 ggplot2 按日期着色,但是当我尝试使用 scale_color_gradient2 自定义颜色时,我收到错误消息 Error in as.Date.numeric(value) : 'origin' must be supplied。
我似乎无法弄清楚如何将来源传递给scale_color_gradient2。
我在下面提供了一个示例。有什么建议吗?
set.seed(1)
x1 <- rnorm(100)
x2 <- rnorm(100)
day <- sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by="day"), 100)
myData <- data.frame(x1, x2, day)
# this plot works as expected
ggplot(myData, aes(x = x1, y = x2, color = day)) + geom_point()
# scale_color_gradient2() asks for an origin, but I can't figure out how to supply one
ggplot(myData, aes(x = x1, y = x2, color = day)) + geom_point() +
scale_color_gradient2()
【问题讨论】:
标签: r date ggplot2 colors tidyverse