0

There is a plot in excel like depth plot. From top to down it has a gradient color. It has nothing to do with line or data. How can I do that in R?

I simple use plot(x, y, type="l"), I could not find any method to make the area of the whole plot gradient.

1 Answers1

0

You can use a solution proposed by B. Auguie using grid.raster or rasterImage:

library(grid)
g <- rasterGrob(blues9, width=unit(1,"npc"), height = unit(1,"npc"),
interpolate = TRUE)
# grid.draw(g)

library(ggplot2)
ggplot(mtcars, aes(factor(cyl))) + # add gradient background
   annotation_custom(g, xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf) +
   geom_bar() # add data layer
Nessi
  • 276
  • 1
  • 4
  • 23