在下面的示例中,我希望最近的点是更深的蓝色阴影(或者更不透明)。
data <- data.frame(x=c(1,2,3,4,5,6,7,8,9,10,11,12),
y=c(1,2,3,4,5,6,7,8,9,10,11,12),
dt=c("2010-12-31","2010-11-30","2010-10-29","2010-09-30",
"2010-08-31","2010-07-30","2010-06-30","2010-05-31","2010-04-30",
"2010-03-31","2010-02-26","2010-01-29"))
p <- ggplot(data, aes(x,y,color=dt)) + geom_point() +
scale_colour_gradient(limits=c("2010-01-29","2010-12_31"),
low="white", high="blue")
print(p)
答案 0 :(得分:5)
dt是因子变量,并且可能缩放_ * _渐变不可用于离散变量。
你可以将dt转换为Date,然后转换为连续变量的整数。
以下是一个例子:
ggplot(data, aes(x,y, colour=as.integer(as.Date(data$dt)))) +
geom_point() +
scale_colour_gradient(limits=as.integer(as.Date(c("2010-01-29","2010-12-31"))),
low="white", high="blue") +
opts(legend.position="none")