1

I want to make time based density plots of a variable for the factor water use management for the data set as follows

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))

I am using the following codes to make density plot for profits across IDs. or may be facet_wrap for group or time?

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()

It gives nice density plots. But for the large data of million rows as I have originally; for instance as given below:

  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))

the codes give an untidy graph. Can we make factor of time say in interval of 20 each to make the graph understandable? or if any other faceting or wrapping can improve the visibility of graph. Please help Thanks

Anoushiravan R
  • 21,622
  • 3
  • 18
  • 41
Sadaf
  • 163
  • 7

1 Answers1

0

take a look at this: 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()

enter image description here

SSDN
  • 276
  • 3
  • 8
  • SSDN thanks for the help. I don't see time on y-axis. I want to see that how profit is changing its density over time. – Sadaf Aug 08 '21 at 11:34
  • The link suggested is not much helpful either. Time based density plot of profits is across IDs!! – Sadaf Aug 08 '21 at 19:07