0

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:

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?

SternK
  • 11,649
  • 22
  • 32
  • 46
  • In the plot you want, each alluvium would track one pixel, or a cohort of pixels, with the same series of zone designations, correct? In that case, the plot needs to know which zone each pixel is designated over each period. Do you have this information? If so, then there are a couple of ways to encode it in the data frame so that {ggalluvial} can understand it. But if not, then you might want to make an area plot instead. – Cory Brunson May 19 '23 at 12:36
  • Thank you Cory. I don't have that information, but it's there in a way. In each period I have the same total amount of pixels, but arranged in different ways. If in period 1 I have 300 pixels in total, with 100pixel per category (A, B, C), and in period 2 I also have 300pixels but with 80pixels in cat A, 100 in cat B and 120 in cat C, is not possible for ggalluvial to understand that there is a flux of 20 pixels from cat A to C? – Agostina Ferro May 22 '23 at 15:26
  • There is not; it could, for example, be that an additional 20 pixels fluxed from A to B and another 20 from B to A, which would produce a "twist" of two alluvia in the diagram as well as the flows between categories. With information on totals each period but not identities, i would suggest making an area plot (using `geom_area()`), at least as a first step. – Cory Brunson May 23 '23 at 17:00
  • Thank you! I will try with an area plot, and also try to get the info I need and then come back – Agostina Ferro May 23 '23 at 17:49

0 Answers0