在刻面图中添加不同的阴影区域

时间:2018-03-18 15:43:01

标签: r ggplot2 facet-wrap

我正在尝试为每年的数据添加阴影区域。年份是行,并且每行的阴影区域应该相同。试过很多方法,但没有任何方面可以解决问题。以下是数据和最新代码示例。应该被遮蔽的区域是开始减去10天。我几乎想把焦点放在“赛季”的十天里。多年。如果有更聪明的方法,请告诉我 问题是阴影区域与数据不匹配。

提前致谢。

 ggplot(x) + 
geom_rect( aes(xmin = onset-10  , xmax = onset, 
                            ymin = -Inf, ymax = Inf), alpha = 0.4) +
geom_col(aes(x = days, y = irish_rules),size= 1)+
geom_col(aes(days, onset), fill = "black",width = 0.1)+
scale_y_continuous(limits = c(0, 40) ) +
theme(axis.title.x = element_blank(),
      axis.title.y=element_blank())+
facet_grid(years ~ stna)+
theme(strip.background = element_blank())

数据充足:

    x <- structure(list(irish_rules = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
2, 8, 0, 0, 1, 0, 0, 7, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 4, 0, 0, 1, 12, 0, 
16, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 
15, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 0, 0, 0, 0, 0, 0, 0, 0, 19, 31, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 
0, 0, 0, 0, 0, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 4, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 
0, 0, 0, 0, 0), years = c(1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 1983L, 
1983L, 1983L, 1983L, 1983L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 1984L, 
1984L, 1984L, 1984L, 1984L), days = c(121L, 122L, 123L, 124L, 
125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 
136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 
147L, 148L, 149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 
158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L, 
169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L, 177L, 178L, 179L, 
180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L, 189L, 190L, 
191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L, 199L, 200L, 201L, 
202L, 203L, 204L, 205L, 206L, 207L, 208L, 209L, 210L, 211L, 212L, 
213L, 214L, 215L, 216L, 217L, 218L, 219L, 220L, 221L, 222L, 223L, 
224L, 225L, 226L, 227L, 228L, 229L, 230L, 231L, 232L, 233L, 234L, 
235L, 236L, 237L, 238L, 239L, 240L, 241L, 242L, 243L, 121L, 122L, 
123L, 124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L, 132L, 133L, 
134L, 135L, 136L, 137L, 138L, 139L, 140L, 141L, 142L, 143L, 144L, 
145L, 146L, 147L, 148L, 149L, 150L, 151L, 152L, 153L, 154L, 155L, 
156L, 157L, 158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 
167L, 168L, 169L, 170L, 171L, 172L, 173L, 174L, 175L, 176L, 177L, 
178L, 179L, 180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L, 
189L, 190L, 191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L, 199L, 
200L, 201L, 202L, 203L, 204L, 205L, 206L, 207L, 208L, 209L, 210L, 
211L, 212L, 213L, 214L, 215L, 216L, 217L, 218L, 219L, 220L, 221L, 
222L, 223L, 224L, 225L, 226L, 227L, 228L, 229L, 230L, 231L, 232L, 
233L, 234L, 235L, 236L, 237L, 238L, 239L, 240L, 241L, 242L, 243L, 
121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L, 130L, 131L, 
132L, 133L, 134L, 135L, 136L, 137L, 138L, 139L, 140L, 141L, 142L, 
143L, 144L, 145L, 146L, 147L, 148L, 149L, 150L, 151L, 152L, 153L, 
154L, 155L, 156L, 157L, 158L, 159L, 160L, 161L, 162L, 163L, 164L, 
165L, 166L, 167L, 168L, 169L, 170L, 171L, 172L, 173L, 174L, 175L, 
176L, 177L, 178L, 179L, 180L, 181L, 182L, 183L, 184L, 185L, 186L, 
187L, 188L, 189L, 190L, 191L, 192L, 193L, 194L, 195L, 196L, 197L, 
198L, 199L, 200L, 201L, 202L, 203L, 204L, 205L, 206L, 207L, 208L, 
209L, 210L, 211L, 212L, 213L, 214L, 215L, 216L, 217L, 218L, 219L, 
220L, 221L, 222L, 223L, 224L, 225L, 226L, 227L, 228L, 229L, 230L, 
231L, 232L, 233L, 234L, 235L, 236L, 237L, 238L, 239L, 240L, 241L, 
242L, 243L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L, 130L, 
131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L, 139L, 140L, 141L, 
142L, 143L, 144L, 145L, 146L, 147L, 148L, 149L, 150L, 151L, 152L, 
153L, 154L, 155L, 156L, 157L, 158L, 159L, 160L, 161L, 162L, 163L, 
164L, 165L, 166L, 167L, 168L, 169L, 170L, 171L, 172L, 173L, 174L, 
175L, 176L, 177L, 178L, 179L, 180L, 181L, 182L, 183L, 184L, 185L, 
186L, 187L, 188L, 189L, 190L, 191L, 192L, 193L, 194L, 195L, 196L, 
197L, 198L, 199L, 200L, 201L, 202L, 203L, 204L, 205L, 206L, 207L, 
208L, 209L, 210L, 211L, 212L, 213L, 214L, 215L, 216L, 217L, 218L, 
219L, 220L, 221L, 222L, 223L, 224L, 225L, 226L, 227L, 228L, 229L, 
230L, 231L, 232L, 233L, 234L, 235L, 236L, 237L, 238L, 239L, 240L, 
241L, 242L, 243L, 244L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 
129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L, 139L, 
140L, 141L, 142L, 143L, 144L, 145L, 146L, 147L, 148L, 149L, 150L, 
151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L, 159L, 160L, 161L, 
162L, 163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L, 171L, 172L, 
173L, 174L, 175L, 176L, 177L, 178L, 179L, 180L, 181L, 182L, 183L, 
184L, 185L, 186L, 187L, 188L, 189L, 190L, 191L, 192L, 193L, 194L, 
195L, 196L, 197L, 198L, 199L, 200L, 201L, 202L, 203L, 204L, 205L, 
206L, 207L, 208L, 209L, 210L, 211L, 212L, 213L, 214L, 215L, 216L, 
217L, 218L, 219L, 220L, 221L, 222L, 223L, 224L, 225L, 226L, 227L, 
228L, 229L, 230L, 231L, 232L, 233L, 234L, 235L, 236L, 237L, 238L, 
239L, 240L, 241L, 242L, 243L, 244L, 122L, 123L, 124L, 125L, 126L, 
127L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 
138L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L, 147L, 148L, 
149L, 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L, 159L, 
160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L, 
171L, 172L, 173L, 174L, 175L, 176L, 177L, 178L, 179L, 180L, 181L, 
182L, 183L, 184L, 185L, 186L, 187L, 188L, 189L, 190L, 191L, 192L, 
193L, 194L, 195L, 196L, 197L, 198L, 199L, 200L, 201L, 202L, 203L, 
204L, 205L, 206L, 207L, 208L, 209L, 210L, 211L, 212L, 213L, 214L, 
215L, 216L, 217L, 218L, 219L, 220L, 221L, 222L, 223L, 224L, 225L, 
226L, 227L, 228L, 229L, 230L, 231L, 232L, 233L, 234L, 235L, 236L, 
237L, 238L, 239L, 240L, 241L, 242L, 243L, 244L), stna = c("Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Birr", 
"Birr", "Birr", "Birr", "Birr", "Birr", "Birr", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Casement", "Casement", "Casement", "Casement", "Casement", 
"Casement", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny", 
"Kilkenny", "Kilkenny", "Kilkenny", "Kilkenny"), onset = c(0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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0, 0, 0, 0, 0)), .Names = c("irish_rules", "years", 
"days", "stna", "onset"), row.names = c(NA, -738L), vars = "id", indices = list(
    0:122, 123:245, 246:368, 369:491, 492:614, 615:737), group_sizes = c(123L, 
123L, 123L, 123L, 123L, 123L), biggest_group_size = 123L, labels = structure(list(
    id = c("1983_Birr", "1983_Casement", "1983_Kilkenny", "1984_Birr", 
    "1984_Casement", "1984_Kilkenny")), row.names = c(NA, -6L
), class = "data.frame", vars = "id", .Names = "id"), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"))

1 个答案:

答案 0 :(得分:2)

猜猜你可能想要得到什么。 你的发病包含许多'0',我觉得这不是你想要的。因此,让我们创建一个没有'0'的新列:

require(dplyr)
dat <- x %>% group_by(stna, years) %>% mutate(onset1 = max(onset))

现在我删除了你的“黑色”阴影区域(并增加了alpha):

   ggplot(dat) + 
      geom_rect( aes(xmin = onset1-10  , xmax = onset1, 
                     ymin = -Inf, ymax = Inf), fill = "grey", alpha = 0.8) +
      geom_col(aes(x = days, y = irish_rules),size= 1)+
      #geom_col(aes(days, onset1), fill = "black",width = 0.1)+
      ... (the rest of your plot)

enter image description here

请注意,我增加了alpha,因为geom_rect()会为每一行绘制一个矩形...(不理想,但更改alpha非常简单的解决方法)