Coloring a geom_histogram by gradient

后端 未结 2 1244
甜味超标
甜味超标 2021-01-12 20:34

I\'m trying to plot a geom_histogram where the bars are colored by a gradient.

This is what I\'m trying to do:

library(ggplot2)
set.seed(1)
df <-          


        
2条回答
  •  萌比男神i
    2021-01-12 20:48

    Not sure you can fill by val because each bar of the histogram represents a collection of points.

    You can, however, fill by categorical bins using cut. For example:

    ggplot(df, aes(val, fill = cut(val, 100))) +
      geom_histogram(show.legend = FALSE)
    

提交回复
热议问题