這是一個令人困惑的標題,但我擁有的是這樣的 df(更大,但是):
df
# A tibble: 10 × 3
week count protest
<int> <dbl> <dbl>
1 1 259. 0
2 2 509. 0
3 3 556. 0
4 4 588. 0
5 5 541. 0
6 6 576. 1
7 7 531. 0
8 8 518. 0
9 9 470. 1
10 10 392. 1
我想要的是在 x 軸上繪制countwithweek的線。但我也想為每個week包含protest == 1.
我做過這樣的事情:
library(ggplot2)
ggplot(berlin_week, aes(x=week, y=count))
geom_line()
geom_vline(aes(xintercept= week[match(1, protest)]), col = "red")

但是正如你所看到的,我只得到了第一個觀察結果protest == 1,而不是protest == 1我想要的所有觀察結果。有任何想法嗎?謝謝!
uj5u.com熱心網友回復:
要為抗議等于 1 的任何一周添加一條紅線,您可以使用以下代碼
ggplot(berlin_week, aes(x=week, y=count))
geom_line()
geom_vline(xintercept = berlin_week$week[berlin_week$protest == 1], color = "red")

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/371933.html
上一篇:用黑線分隔散點圖點
