如何用渐变色填充下方(sp)线以下的区域?
这个例子是在Inkscape中绘制的 - 但我需要垂直渐变 - 不是水平的.
从零到正的间隔==从白色到红色.
从零到负的间隔==从白色到红色.

有没有可以做到这一点的包?
我编造了一些源数据....
set.seed(1)
x<-seq(from = -10, to = 10, by = 0.25)
data <- data.frame(value = sample(x, 25, replace = TRUE), time = 1:25)
plot(data$time, data$value, type = "n")
my.spline <- smooth.spline(data$time, data$value, df = 15)
lines(my.spline$x, my.spline$y, lwd = 2.5, col = "blue")
abline(h = 0)
Run Code Online (Sandbox Code Playgroud) 有了这个数据:
df <- data.frame(value =c(20, 50, 90),
group = c(1, 2,3))
Run Code Online (Sandbox Code Playgroud)
我可以得到一个条形图:
df %>% ggplot(aes(x = group, y = value, fill = value)) +
geom_col() +
coord_flip()+
scale_fill_viridis_c(option = "C") +
theme(legend.position = "none")
Run Code Online (Sandbox Code Playgroud)
但我希望这些条形的颜色根据它们在 中的相应值而变化value。
我已经设法使用以下方法更改它们geom_raster:
ggplot() +
geom_raster(aes(x = c(0:20), y = .9, fill = c(0:20)),
interpolate = TRUE) +
geom_raster(aes(x = c(0:50), y = 2, fill = c(0:50)),
interpolate = TRUE) +
geom_raster(aes(x = c(0:90), y = 3.1, fill = c(0:90)),
interpolate = …Run Code Online (Sandbox Code Playgroud)