geom_text() & 颜色渐变

geom_text() & color gradient

我想在 geom_text 函数上设置一个颜色渐变,从绿色代表低,红色代表高。我的代码如下:

mydata <-  data.frame(R_Test_Data)

datatime <- mydata$TIMESTAMP
wind_speed <- mydata$WS_ms_Avg
wind_direction <-mydata$WS_ms_WVc

ggplot(data = mydata, aes(x = datatime, y = wind_speed))+
  geom_line() +
  geom_text(aes(angle=-wind_direction + 270), label="→", 
            colour = wind_speed, size = 7 ) +
 scale_colour_gradient(low="green", high="red") 

我正在寻找类似这样的东西:

将颜色映射到数值变量 - 例如这通过在 aes 中指定 color=y 将颜色映射到 y

set.seed(1);df <- data.frame(x = 1:10, y = 1:10, angle = runif(10,90,180))
library(ggplot2)
ggplot(df, aes(x,y)) + 
  geom_text(aes(angle=angle, color=y), label="-", size = 12) + 
  scale_colour_distiller(palette="RdYlGn")