0

我正在尝试重新创建这个山脊图:

https://i.stack.imgur.com/QAFs1.jpg

但是,我似乎无法让曲线出现在情节上,正如您可能已经猜到的那样,我对 r 很陌生,所以我几乎复制了https://bytefish.de/blog/timeseries_databases_5_visualization_with_ggridges /到达我所在的位置。

这是代码:

eustockmark_index <- fortify.zoo(EuStockMarkets)

eustockmark_index$Index=as.factor(eustockmark_index$Index)
eustockmark_index$Index=factor(eustockmark_index$Index,levels=c(1991,1992,1993,1994,1995,1996,1997,1998))
eustockmark_index$Index= trimws(eustockmark_index$Index)

eustockmark_index

ggplot(eustockmark_index, aes(x = `DAX`, y =`Index`,fill=..x..)) +
  geom_density_ridges_gradient() +
  labs(title = "DAX",
       x = " ",
       y = " ")+
  scale_fill_viridis(option = "C")

另外,如果有人能解释为什么我的 Y 轴顶部有 NA,那将是了不起的。非常感谢!

4

1 回答 1

2

这似乎使用以下方法重新创建您的情节dplyr

library(datasets)
library(tidyverse)
library(ggridges)
library(zoo)

data <- fortify.zoo(EuStockMarkets) %>% mutate(Index = as_factor(floor(Index)))

ggplot(data, aes(x = DAX, y = Index, fill = ..x..)) +
  geom_density_ridges_gradient() +
  scale_fill_viridis_c(option = "C",
                       direction = -1,
                       guide = "none") +
  labs(title = "DAX", x = "", y = "")

输出

选项direction = -1guide = "none"forscale_fill_viridis_c不是必需的,但似乎在显示的图中使用。根据需要注释掉。

请在将来提出问题时制作MWE 。

于 2019-11-02T16:56:03.687 回答