【问题标题】:Time series density plot across factors for large data set大型数据集跨因子的时间序列密度图
【发布时间】:2021-10-12 09:53:39
【问题描述】:

我想为数据集的因子用水管理制作基于时间的密度图,如下所示

Seed(123)
ID = rep(c("BAU","IMP","SGR","CR"), each=25)
Time = rep (c(1,2,3,4,5), each = 20)
data <- data.frame( ID, Time,  profits = runif(100,0,1))

我正在使用以下代码制作跨 ID 利润的密度图。或者可能是组或时间的 facet_wrap?

library(ggridges)
ggplot(
  data, aes(x = profits, y=as.factor( Time), group = ID, fill=stat(x))) +
  geom_density_ridges_gradient(scale = 3, size = 0.3, rel_min_height = 0.01) + 
  scale_fill_viridis_c(name = "Profits", option = "C") +
  labs(title = 'Total Profits')  + facet_wrap(~ID, scales = "free")+
  theme_classic()

它给出了很好的密度图。但是对于我原来拥有的百万行的大数据;例如如下所示:

  Seed(123)
ID = rep(c("BAU","IMP","SGR","CR"), each=5000)
Time = rep (c(1:1000), each = 20)
data <- data.frame( ID, Time,  profits = runif(20000,0,1))

代码给出了一个不整洁的图表。我们可以让时间因素以 20 的间隔表示,以使图表易于理解吗?或者如果任何其他刻面或包装可以提高图形的可见性。请帮忙 谢谢

【问题讨论】:

    标签: r ggplot2 time-series facet density-plot


    【解决方案1】:

    看看这个: https://stackoverflow.com/a/55852972/13142581

    Seed(123)
    ID = rep(c("BAU","IMP","SGR","CR"), each=25)
    Time = rep (c(1,2,3,4,5), each = 20)
    data <- data.frame( ID, Time,  profits = runif(100,0,1))
    
    library(ggridges)
    ggplot(
      data, aes(x = profits, y=as.character(ID), group = as.character(Time), fill=stat(x))) +
      geom_density_ridges_gradient(scale = 3,  rel_min_height = 0.01) + 
      scale_fill_viridis_c(name = "Profits", option = "C") +
      labs(title = 'Total Profits')  + facet_wrap(~ID, scales = "free")+
      theme_classic()
    

    【讨论】:

    • SSDN 感谢您的帮助。我在 y 轴上看不到时间。我想看看随着时间的推移,利润是如何改变其密度的。
    • 建议的链接也没有多大帮助。基于时间的利润密度图是跨 ID 的!!
    猜你喜欢
    • 1970-01-01
    • 2016-09-06
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多