我正在尝试创建一个ridgeplot,该图根据单独的变量沿x轴显示不同的颜色区域。
有点像fill
函数,但是它不会对整个“山脊”进行着色,而是仅对部分着色,具体取决于满足某些条件的位置。
以下是一个小例子:
library(mosaicData) # for the dataset
> head(Weather)
# A tibble: 6 x 25
# Groups: city, year [1]
city date year month day high_temp avg_temp low_temp high_dewpt avg_dewpt low_dewpt high_humidity avg_humidity low_humidity
<chr> <date> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Auck~ 2016-01-01 2016 1 1 68 65 62 64 60 55 100 82 68
2 Auck~ 2016-01-02 2016 1 2 68 66 64 64 63 61 100 94 88
3 Auck~ 2016-01-03 2016 1 3 77 72 66 70 67 64 100 91 74
4 Auck~ 2016-01-04 2016 1 4 73 66 60 66 60 54 100 76 53
5 Auck~ 2016-01-05 2016 1 5 69 62 55 55 52 48 82 69 56
6 Auck~ 2016-01-06 2016 1 6 69 63 57 54 51 46 88 65 46
# ... with 11 more variables: high_hg <dbl>, avg_hg <dbl>, low_hg <dbl>, high_vis <dbl>, avg_vis <dbl>, low_vis <dbl>, high_wind <dbl>,
# avg_wind <dbl>, low_wind <dbl>, precip <chr>, events <chr>
这是ridgeplot的代码:
library(ggplot2)
library(ggridges)
ggplot(Weather, aes(x = date, y = city, height = avg_temp)) +
geom_density_ridges(stat = "identity", fill = 'black', scale = 1, alpha = .4) +
theme_ridges(center_axis_labels = TRUE)
以该数据集为例,我想做的是:
height = avg_temp
,high_temp
(一个变量,