在ggplot2中创建从上到下的淡入淡出/渐变geom_density

问题描述

我想创建一个具有从上到下渐变的geom_density。这只是为了美观。例如,此图的淡入淡出是我想要实现的:

enter image description here

最小工作示例:

加载库:

library(ggplot2)
library(dplyr)

这里有一些数据

dat <- structure(list(date = structure(c(18335,18336,18337,18338,18339,18340,18341,18342,18343,18344,18345,18346,18347,18348,18349,18350,18351,18352,18353,18354,18355,18356,18357,18358,18359,18360,18361,18362,18363,18364,18365,18366,18367,18368,18369,18370,18371,18372,18373,18374,18375,18376,18377,18378,18379,18380,18381,18382,18383,18384,18385,18386,18387,18388,18389,18390,18391,18392,18393,18394,18395,18396,18397,18398,18399,18400,18401,18402,18403,18404,18405,18406,18407,18408,18409,18410,18411,18412,18413,18414,18415,18416,18417,18418,18419,18420,18421,18422,18423,18424,18425,18426,18427,18428,18429,18430,18431,18432,18433,18434,18435,18436,18437,18438,18439,18440,18441,18442),class = "Date"),n = c(49L,121L,152L,142L,137L,138L,129L,144L,187L,245L,337L,363L,360L,374L,386L,399L,404L,395L,402L,398L,389L,392L,409L,419L,414L,391L,388L,377L,396L,275L,393L,394L,322L,383L,397L,343L,384L,366L,358L,375L,378L,373L,368L,369L,352L,367L,357L,347L,329L,361L,340L,334L,359L,335L,325L,297L,326L,350L,323L,232L,226L,234L,222L,221L,191L,204L,174L,76L,58L,52L,32L,29L,27L,21L,22L,20L,13L,10L,12L,3L,4L,3L)),row.names = c(NA,-108L),class = c("tbl_df","tbl","data.frame")) %>%
  uncount(n)

这就是我要淡出的geom_density

ggplot(dat,aes(date)) +
    geom_density(stat = "density",color = "black",fill = "black",lwd = .75)

这是上面的代码生成的图:

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)