0

I am trying to make a plot (CCDF of cascade size) similar to this page.

Below, is the result of print(cascades[seq(2)]), showing two cascades:

[[1]]
         time magnitude
 1:     0.000      5126
 2:  1062.336      2127
 3:  1638.698       175

[[2]]
         time magnitude
 1:     0.000      1472
 2:    18.808      2851
 3:    30.931      1438
 4:    95.205       685

and here is the code:

mean_value <- mean(sapply(cascades, nrow))
ggplot(data.frame(size = sapply(cascades, nrow))) +
  stat_ecdf(aes(size, 1 - ..y..)) +
  scale_x_log10() + scale_y_log10() +
  geom_vline(xintercept = mean_value, linetype=2, color = 'red') +
  geom_text(data=data.frame(), aes(x = mean_value, y = 1e-3, label= sprintf('mean: %s', round(mean_value, 2))), color= 'red', angle=90, vjust=-0.11) +
  xlab('cascade size') +
  ylab('CCDF')

When I run the above code, it shows the following error:

`geom_path()`: Each group consists of only one observation.
ℹ Do you need to adjust the group aesthetic?
Warning messages:
1: In self$trans$transform(x) : NaNs produced
2: Transformation introduced infinite values in continuous y-axis 
3: Removed 113 rows containing missing values (`geom_step()`).

Here is the resulting plot: enter image description here

I found several similar posts (e.g., (1) and (2)), and I added group=1 to the aes as following but I still get the same error:

  • (aes(size, 1 - ..y.., group=1))
  • geom_vline(xintercept = mean_value, linetype=2, color = 'red', aes(group=1))
  • geom_text(data=data.frame(), aes(x = mean_value, y = 1e-3, label= sprintf('mean: %s', round(mean_value, 2)), group=1)

I appreciate if someone let me know what part I'm doing wrong.

mOna
  • 2,341
  • 9
  • 36
  • 60

0 Answers0