如何用R重现这个动态分布图?

Pau*_*eux 3 plot r ggridges

G Elliot Moris 使用动态分布图显示了政治两极分化. 1963  -  2013年美国政治两极分化的情节

从这个问题:如何使用'facet'在GGPLOT中创建多个密度图我设法使用facet使用虚拟数据重现类似的图:

library(ggplot2)
set.seed(101)
dtf <- data.frame(variable = c(rnorm(1000),
                               rnorm(1000) + rep(1:10/2,each =100)),
                  group = rep(c("a","b"), each = 1000),
                  year = rep(2001:2010, each=100))
ggplot(dtf) +
    geom_density(aes(x = variable, fill = group)) +
    facet_grid(year ~.)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

但我希望这些分布在原始情节中重叠.这些图是否有特定的名称,是否可以用R复制它们?

[编辑] 此全局温度分布图中提供了类似图的动态版本.

Ian*_*Ian 9

更新:用于创建此图的包现在名为"ggridges".

你需要ggjoy包.这是一个需要整理的粗略版本:


devtools::install_github("clauswilke/ggjoy")
library(ggjoy)
library(ggplot2)

#Create data frame
set.seed(101)
dtf <- data.frame(variable = c(rnorm(1000),
                               rnorm(1000) + rep(1:10/2,each =100)),
                  group = rep(c("a","b"), each = 1000),
                  year = rep(2001:2010, each=100))

# Use ggplot2 and ggjoy packages  
ggplot(dtf,aes(x = variable, y = as.factor(year), fill = group)) +
  geom_joy(scale = 2,alpha = .5,rel_min_height = 0.01) + theme_joy() 
#> Picking joint bandwidth of 0.347
Run Code Online (Sandbox Code Playgroud)