Stacked barplot with colour gradients for each bar

前端 未结 2 2040
迷失自我
迷失自我 2020-12-05 22:08

I want to color a stacked barplot so that each bar has its own parent colour, with colours within each bar to be a gradient of this parent colour.

Example:

2条回答
  •  鱼传尺愫
    2020-12-05 22:13

    An easier approach to achieve a colour gradient is to use alpha to change the transparency of the colour. However, this can have unintended consequences as transparency means you can see the guidelines through the plot.

    library(ggplot2)
    
    ggplot(diamonds, aes(color, alpha = clarity)) + 
      geom_bar(aes(fill = color), colour = "grey") +
      scale_alpha_discrete(range = c(0,1))
    

提交回复
热议问题