Home > Mobile >  Calendar like plot with highlighted some consecutive days in R
Calendar like plot with highlighted some consecutive days in R

Time:07-11

I have daily time-series data for 35 years about the presence and absence of rainfall in winter seasons for around 10 stations. Following is the part of data of one station where, in the third column, 1 indicates the presence and 0 indicates the absence of rainfall:

> dput(data_f[1:1500,])
structure(list(monthDay = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 
33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 
46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 
59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 
72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 
85L, 86L, 87L, 88L, 89L, 90L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 
22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 
35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 
48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 
61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 
74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 
87L, 88L, 89L, 90L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 
24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 
37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 
50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 
63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 
76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 
89L, 90L, 91L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 
38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 
51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 
64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 
77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 
90L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 
14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 
27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 
40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 
53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 
66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 
79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 1L, 
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 
16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 
29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 
42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 
55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 
81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 1L, 2L, 3L, 
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 
18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 
31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 
44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 
57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 
70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 
83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 1L, 2L, 3L, 4L, 
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 
32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 
45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 
58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 
71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 
84L, 85L, 86L, 87L, 88L, 89L, 90L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 
21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 
47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 
60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 
73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 
86L, 87L, 88L, 89L, 90L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 
10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 
23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 
36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 
49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 
62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 
75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 
88L, 89L, 90L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 
25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 
38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 
51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 
64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 
77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 
90L, 91L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 
26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 
39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 
52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 
65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 
78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 
28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 
41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 
54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 
67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 
80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 1L, 2L, 
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 
17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 
30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 
43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 
56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 
69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 
82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 1L, 2L, 3L, 4L, 
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 
32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 
45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 
58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 
71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 
84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 1L, 2L, 3L, 4L, 5L, 6L, 
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 
33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 
46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 
59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 
72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 
85L, 86L, 87L, 88L, 89L, 90L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 
22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 
35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 
48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L), .Label = c("Dec 1", 
"Dec 2", "Dec 3", "Dec 4", "Dec 5", "Dec 6", "Dec 7", "Dec 8", 
"Dec 9", "Dec 10", "Dec 11", "Dec 12", "Dec 13", "Dec 14", "Dec 15", 
"Dec 16", "Dec 17", "Dec 18", "Dec 19", "Dec 20", "Dec 21", "Dec 22", 
"Dec 23", "Dec 24", "Dec 25", "Dec 26", "Dec 27", "Dec 28", "Dec 29", 
"Dec 30", "Dec 31", "Jan 1", "Jan 2", "Jan 3", "Jan 4", "Jan 5", 
"Jan 6", "Jan 7", "Jan 8", "Jan 9", "Jan 10", "Jan 11", "Jan 12", 
"Jan 13", "Jan 14", "Jan 15", "Jan 16", "Jan 17", "Jan 18", "Jan 19", 
"Jan 20", "Jan 21", "Jan 22", "Jan 23", "Jan 24", "Jan 25", "Jan 26", 
"Jan 27", "Jan 28", "Jan 29", "Jan 30", "Jan 31", "Feb 1", "Feb 2", 
"Feb 3", "Feb 4", "Feb 5", "Feb 6", "Feb 7", "Feb 8", "Feb 9", 
"Feb 10", "Feb 11", "Feb 12", "Feb 13", "Feb 14", "Feb 15", "Feb 16", 
"Feb 17", "Feb 18", "Feb 19", "Feb 20", "Feb 21", "Feb 22", "Feb 23", 
"Feb 24", "Feb 25", "Feb 26", "Feb 27", "Feb 28", "Feb 29"), class = "factor"), 
    stat_year = c(1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 
    1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 
    1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 
    1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 
    1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 
    1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 
    1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 
    1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 
    1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 1982, 
    1982, 1982, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 
    1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 
    1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 
    1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 
    1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 
    1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 
    1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 
    1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 
    1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 1983, 
    1983, 1983, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 
    1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 
    1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 
    1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 
    1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 
    1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 
    1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 
    1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 
    1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 1984, 
    1984, 1984, 1984, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 
    1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 
    1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 
    1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 
    1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 
    1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 
    1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 
    1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 
    1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 1985, 
    1985, 1985, 1985, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 
    1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 
    1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 
    1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 
    1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 
    1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 
    1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 
    1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 
    1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 1986, 
    1986, 1986, 1986, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 
    1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 
    1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 
    1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 
    1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 
    1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 
    1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 
    1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 
    1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 1987, 
    1987, 1987, 1987, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 
    1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 
    1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 
    1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 
    1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 
    1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 
    1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 
    1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 
    1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 1988, 
    1988, 1988, 1988, 1988, 1989, 1989, 1989, 1989, 1989, 1989, 
    1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 
    1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 
    1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 
    1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 
    1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 
    1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 
    1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 
    1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 1989, 
    1989, 1989, 1989, 1989, 1990, 1990, 1990, 1990, 1990, 1990, 
    1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 
    1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 
    1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 
    1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 
    1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 
    1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 
    1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 
    1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 1990, 
    1990, 1990, 1990, 1990, 1991, 1991, 1991, 1991, 1991, 1991, 
    1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 
    1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 
    1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 
    1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 
    1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 
    1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 
    1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 
    1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 1991, 
    1991, 1991, 1991, 1991, 1992, 1992, 1992, 1992, 1992, 1992, 
    1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 
    1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 
    1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 
    1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 
    1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 
    1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 
    1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 
    1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 1992, 
    1992, 1992, 1992, 1992, 1992, 1993, 1993, 1993, 1993, 1993, 
    1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 
    1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 
    1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 
    1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 
    1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 
    1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 
    1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 
    1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 1993, 
    1993, 1993, 1993, 1993, 1993, 1994, 1994, 1994, 1994, 1994, 
    1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 
    1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 
    1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 
    1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 
    1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 
    1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 
    1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 
    1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994, 
    1994, 1994, 1994, 1994, 1994, 1995, 1995, 1995, 1995, 1995, 
    1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 
    1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 
    1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 
    1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 
    1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 
    1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 
    1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 
    1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 1995, 
    1995, 1995, 1995, 1995, 1995, 1996, 1996, 1996, 1996, 1996, 
    1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 
    1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 
    1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 
    1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 
    1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 
    1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 
    1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 
    1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 1996, 
    1996, 1996, 1996, 1996, 1996, 1996, 1997, 1997, 1997, 1997, 
    1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 
    1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 
    1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 
    1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 
    1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 
    1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 
    1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 
    1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 1997, 
    1997, 1997, 1997, 1997, 1997, 1997, 1998, 1998, 1998, 1998, 
    1998, 1998, 1998, 1998, 1998, 1998, 1998, 1998, 1998, 1998, 
    1998, 1998, 1998, 1998, 1998, 1998, 1998, 1998, 1998, 1998, 
    1998, 1998, 1998, 1998, 1998, 1998, 1998, 1998, 1998, 1998, 
    1998, 1998, 1998, 1998, 1998, 1998, 1998, 1998, 1998, 1998, 
    1998, 1998, 1998, 1998, 1998, 1998, 1998, 1998, 1998, 1998, 
    1998, 1998), rainfall = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
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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, 0, 0, 0, 0, 0, 1, 
    0, 1, 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, 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)), row.names = c(NA, -1500L), class = c("tbl_df", 
"tbl", "data.frame"))

I have to visualize the rainfall and consecutive wet days for each year in a calendar format plot. Here consecutive wet days are defined as when at least 3 consecutive days received rainfall. If 3 or more than 3 consecutive days (any number) received rainfall I will consider it as a single event.

I am able to plot the rainfall days using the following script in r

sy <- min(data_f$stat_year)
ey <- max(data_f$stat_year)

data_f$monthDay <- factor(data_f$monthDay, levels=unique(data_f$monthDay))

p<-ggplot(data_f, aes(x=monthDay, y=stat_year, fill= rainfall))   
    geom_tile(color = "black",
              lwd = 0.01,
              linetype = 1)  
    #coord_equal() 
    scale_fill_gradient(low = "white", high = "orange") 
    scale_y_continuous(breaks = seq(sy 1,ey-1, 1)) 
    labs(x="Day", y= "Year") 
    theme_classic(base_size=10) 
    theme(legend.position = "none",
          axis.line = element_blank(),
          axis.ticks = element_blank(),
          axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))

This gives the following output enter image description here

Now I want to distinguish consecutive wet days in that plot with a red box around it like this on the first consecutive wet days enter image description here

which I can do by creating rectangular boxes manually for that events by the following script

p annotate("rect",xmin = 32.5,xmax =36.5,ymin =1989.5,ymax =1990.5,alpha = 0,color= "red",size=1.5)

But this solution is not feasible as I have to prepare for many stations. Is there any excellent solution that can ease my work? If I can solve for a station, I can iterate for all stations in R.

Thank you in advance for your help -:)

CodePudding user response:

Here's an approach using dplyr. Within each stat_year, I make a new group every time it switches between rain and no rain. Then I track the start and end of each of those groups. I keep rainy groups at least three days.

Then we can plot that using geom_rect using that data set. To align with the plot I'm using as.numeric(FACTOR_VARIABLE).

library(dplyr)
outlines <- data_f %>%
  group_by(stat_year) %>%
  mutate(rain = rainfall > 0, 
         grp = cumsum(rain != lag(rain, default = TRUE))) %>% 
  group_by(rain, stat_year, grp) %>% 
  summarize(start = first(monthDay),
            end = last(monthDay),
            length = as.numeric(end) - as.numeric(start)   1, .groups = "drop") %>% 
  filter(rain, length >= 3)


ggplot(data_f, aes(x=monthDay, y=stat_year, fill= rainfall))   
  geom_tile(color = "black",
            lwd = 0.01,
            linetype = 1)  
  geom_rect(data = outlines, inherit.aes = FALSE,
            aes(xmin = as.numeric(start) - 0.5, xmax = as.numeric(end)   0.5,
                ymin = stat_year - 0.5, ymax = stat_year   0.5),
            fill = NA, color = "red")  
  ...

enter image description here

  •  Tags:  
  • r
  • Related