【发布时间】:2022-01-21 01:22:54
【问题描述】:
我正在尝试使用 geom_rect 为我的时间序列 (values) 的部分着色,基于 state。
idx state value
1 1 S 0.00000
2 2 S 0.00001
3 3 S 0.00016
4 4 S 0.00003
5 5 S 0.00047
6 6 S 0.00002
7 7 J 0.00048
8 8 J 0.00011
9 9 J 0.00001
10 10 J 0.00753
'data.frame': 245 obs. of 3 variables:
$ idx : chr "1" "2" "3" "4" ...
$ state: chr "S" "S" "S" "S" ...
$ value: num 0 0.00001 0.00016 0.00003 ...
代码:
ggplot(new, aes(x = idx, y = value)) +
geom_rect(aes(xmin = idx, xmax = dplyr::lead(idx), ymin = -Inf, ymax = Inf, fill = factor(state)),
alpha = .3) +
geom_line(aes(x = idx, y = value)) +
theme(axis.title.y = element_blank())
很遗憾,我收到一个错误:
geom_path:每个组仅包含一个观察值。是否需要调整 群体审美?
我做错了什么?
【问题讨论】: