R 用渐变填充几何图形区域(ggplot2)

R 用渐变填充几何图形区域(ggplot2),r,ggplot2,gradient,R,Ggplot2,Gradient,我在将渐变填充应用于面积图时遇到一些问题 数据如下: > df year annual 1 1960 0.0100 2 1961 -0.2700 3 1962 -0.3450 4 1963 -0.6508 5 1964 -0.9458 6 1965 -0.2458 7 1966 0.9492 8 1967 0.5383 9 1968 0.6275 10 1969 0.0000 我已经为渐变设置了一个colorrmppalete,我知道这是可行的 spi

我在将渐变填充应用于面积图时遇到一些问题

数据如下:

> df
   year  annual
1  1960  0.0100
2  1961 -0.2700
3  1962 -0.3450
4  1963 -0.6508
5  1964 -0.9458
6  1965 -0.2458
7  1966  0.9492
8  1967  0.5383
9  1968  0.6275
10 1969  0.0000
我已经为渐变设置了一个
colorrmppalete
,我知道这是可行的

spi.cols <- colorRampPalette(c("darkred","red","yellow","white","green","blue","darkblue"),space="rgb")
我还指定了我希望在渐变中使用的中断,但我不确定如何使用它。我试图在
比例填充梯度n的值中使用此选项,但未成功

spi.break这可能有帮助:相关:
ggplot(df, aes(x = year)) +
   geom_polygon(aes(y = annual, fill = annual)) +
   theme_classic() +
   scale_fill_gradientn(colours = spi.cols(12), limits = c(-2.5, 2.5), guide = "legend")
spi.breaks <- c(-2.5,-2,-1.6,-1.3,-0.8,-0.5,0.5,0.8,1.3,1.6,2,2.5)