I am new using the ggalluvial package. Currently I am working with a dataset of pixels forming different types of land cover. What I want to represent is the migration of pixels from one cover type to another along the years (four periods: 2001-2005, 2006-2010, 2011-2015 and 2016-2020). Below is a sample of the dataset that I am working with:
zone periodo pixCob migrados
<fct> <fct> <dbl> <dbl>
1 10 [2000,2005] 28518204. 78881
2 10 (2005,2010] 28108472. -460939
3 10 (2010,2015] 27613293. -477254
4 10 (2015,2020] 27327443. -46403
5 20 [2000,2005] 8243171 127053
6 20 (2005,2010] 8580581. 255097
Where zone is the cover type (I have 5 land cover types), pixCob is the amount of pixels forming the respective cover type in each period of time and migrados is the difference between the last year and the first year of the same period (this means the amount of pixels "new" or "lost" for the cover type in each period of time)
The output of str() is:
str(datos_resumidos)
gropd_df [20 × 4] (S3: grouped_df/tbl_df/tbl/data.frame)
$ zone : Factor w/ 5 levels "10","20","40",..: 1 1 1 1 2 2 2 2 3 3 ...
$ periodo : Factor w/ 4 levels "[2000,2005]",..: 1 2 3 4 1 2 3 4 1 2 ...
$ pixCob : num [1:20] 28518204 28108472 27613293 27327443 8243171 ...
$ migrados: num [1:20] 78881 -460939 -477254 -46403 127053 ...
- attr(*, "groups")= tibble [5 × 2] (S3: tbl_df/tbl/data.frame)
..$ zone : Factor w/ 5 levels "10","20","40",..: 1 2 3 4 5
..$ .rows: list<int> [1:5]
.. ..$ : int [1:4] 1 2 3 4
.. ..$ : int [1:4] 5 6 7 8
.. ..$ : int [1:4] 9 10 11 12
.. ..$ : int [1:4] 13 14 15 16
.. ..$ : int [1:4] 17 18 19 20
.. ..@ ptype: int(0)
I'm trying to do an alluvial diagram with four axis (named periodo: 2001-2005, 2006-2010, 2011-2015 and 2016-2020), each axis would be divided in the 5 land cover types (named zones) and the flow would me made by migrados; showing fluxes that represent groups of pixels that stay in the same land cover type and anther groups that move to another land cover typer between the periods. y = pixCob cause is the total amount of pixels forming each land cover type for each period of time.
The code to accomplish this is:
ggplot(datos_resumidos, aes(x = periodo, stratum = migrados, alluvium = zone, y = pixCob, fill = zone, label = zone)) + scale_x_discrete(expand = c(.1, .1)) + geom_alluvium(aes(fill = zone)) + geom_stratum(alpha = .5) + geom_text(stat = "stratum") + theme(legend.position = "none")
I dont get any error, but I dont get any divition in the fluxes either, so the full land cover of one period "moves" completly to the other period (this means that there is no migration, and thats not correct). This is what I get:
I believe this is the best graph to represent what Im trying to show, but of course I'm open to other suggestions.
I have been doing some research but I didnt find the answer, maybe the input data is not correct? How can I properly develop the desired alluvial diagram using this data?