[ad_1]

```
library(ggplot2)
library(maps)
library(sf)
library(rgdal)
library(here)
```

I have an extensive initial dataset that contains this information:

```
> dput(df[sample(nrow(df), 20),])
structure(list(lat = c("60", "63", "63", "55", "65", "63", "55",
"59", "67", "63", "59", "56", "56", "59", "63", "58", "63", "56",
"68", "64"), long = c("16", "20", "20", "14", "22", "20", "14",
"15", "23", "14", "17", "16", "16", "15", "19", "14", "20", "16",
"18", "20"), date = c("1993-04-08", "2021-03-28", "2013-04-05",
"2015-01-24", "2008-04-06", "2015-03-31", "2021-03-17", "2003-03-16",
"2012-04-15", "2020-04-15", "2011-03-20", "2008-01-29", "2021-03-26",
"2021-02-06", "2008-04-08", "2017-02-28", "2018-04-04", "1970-04-06",
"2014-04-01", "2020-03-26"), julian_day = c(98, 87, 95, 24, 97,
90, 76, 75, 106, 106, 79, 29, 85, 37, 99, 59, 94, 96, 91, 86),
year = c(1993L, 2021L, 2013L, 2015L, 2008L, 2015L, 2021L,
2003L, 2012L, 2020L, 2011L, 2008L, 2021L, 2021L, 2008L, 2017L,
2018L, 1970L, 2014L, 2020L), decade = c("1990-1999", "2020-2029",
"2010-2019", "2010-2019", "2000-2009", "2010-2019", "2020-2029",
"2000-2009", "2010-2019", "2020-2029", "2010-2019", "2000-2009",
"2020-2029", "2020-2029", "2000-2009", "2010-2019", "2010-2019",
"1970-1979", "2010-2019", "2020-2029"), time = c(14L, 17L,
16L, 16L, 15L, 16L, 17L, 15L, 16L, 17L, 16L, 15L, 17L, 17L,
15L, 16L, 16L, 12L, 16L, 17L), lat_grouped = c("2", "2",
"2", "1", "3", "2", "1", "1", "3", "2", "1", "1", "1", "1",
"2", "1", "2", "1", "3", "2"), year_centered = structure(c(6,
34, 26, 28, 21, 28, 34, 16, 25, 33, 24, 21, 34, 34, 21, 30,
31, -17, 27, 33), class = "AsIs")), row.names = c(5509L,
51388L, 30786L, 33800L, 19913L, 35297L, 50749L, 9479L, 28765L,
48727L, 25803L, 18063L, 51224L, 49855L, 20086L, 38116L, 41958L,
666L, 33232L, 47564L), class = "data.frame")
```

As you can see, it contains observation data across time (1 line is one observation). The essential information linked to this data is latitude and date information.

From the latitudes, I have regrouped 3 distinct groups (south-middle-north, 1-2-3 in this order). I have, in particular, from the date, associated a Julian day and a decade.

I am looking for how to represent the change over time within my observations per group of latitude, with a step of time equal to 1 decade, and for each decade with a succession of 15 Julian days intervals. The Julian days start at Julian day n°15 and stop at n°155.

Here I am considering only the first decade of my dataset because I presume that if I can make it for one decade, then I would be able to repeat it 🙂

```
sub1 = subset(df, decade == "1950-1959")
```

One issue is that the number of observations is not uniform across the whole period, so I weighted the amount of observations by dividing the number of observations per day per decade per latitude group by the total number of observations per decade per latitude group:

```
sub1_pond = sub1 %>%
group_by(decade, julian_day, lat_grouped) %>%
count()
colnames(sub1_pond) = c("decade", "julian_day", "lat_grouped", "nb_obs_perday_perdecade_perlatgroup")
ponderate = sub1_pond %>%
group_by(decade, lat_grouped) %>%
summarize(sum_nb_tot = sum(nb_obs_perday_perdecade_perlatgroup))
sub1_pond = sub1_pond %>%
ungroup %>%
left_join(.,
ponderate) %>%
mutate(newval = nb_obs_perday_perdecade_perlatgroup/sum_nb_tot)
sub1_pond_range <- sub1_pond %>%
mutate(ranges = cut(julian_day,
seq(0, 155, 15))) %>%
group_by(ranges, lat_grouped) %>%
dplyr::summarize(sums = sum(newval)) %>%
as.data.frame() %>%
arrange(., lat_grouped)
> sub1_pond_range
ranges lat_grouped sums
1 (15,30] 1 0.05357143
2 (30,45] 1 0.16071429
3 (45,60] 1 0.19642857
4 (60,75] 1 0.21428571
5 (75,90] 1 0.14285714
6 (90,105] 1 0.21428571
7 (105,120] 1 0.01785714
8 (60,75] 2 0.05555556
9 (75,90] 2 0.11111111
10 (90,105] 2 0.77777778
11 (105,120] 2 0.05555556
```

On the other side, I have this map on which I would like to map the change:

```
sweden <- st_read(here("C:/Users/HP/Desktop/", "SWE_ADM0", "SWE_ADM0.shp"),
layer = "SWE_ADM0") |>
st_simplify(dTolerance = 1e3)
```

But here, I am unable to keep going. What I would like to obtain for my ongoing decade would be something like:

- one map per 15 days interval (each interval would be comparable to the same gap in the other decades)
- on each map, for each group of latitude, a colour gradient showing how “dense” is the data using the weighted amount of observations
- if there is no observation at one 15-days interval, still having a map for the corresponding interval with no data represented on it

I am not sure how pertinent this visualization will be, but I do not have much experience in data visualization, and this problem is quite complex for me. If you feel that I am wrong about my design idea, please feel free to criticize it.

If some information is missing, please forgive me, and I can update my post 🙂

Many thanks for the precious help.

[ad_2]