ggplot error `geom_path()`: 每组只包含一个观察值

问题描述 投票:0回答:0

我正在尝试制作类似于this page的情节(级联大小的CCDF)。

下面,是

print(cascades[seq(2)])
的结果,显示了两个级联:

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

这是代码:

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

当我运行上面的代码时,它显示以下错误:

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

这是结果图:

我发现了几个类似的帖子(例如,(1)(2)),我将 group=1 添加到 aes 如下,但我仍然得到相同的错误:

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

如果有人让我知道我做错了什么,我将不胜感激。

r ggplot2 plot aes
© www.soinside.com 2019 - 2024. All rights reserved.