Skip to contents

Produce a data.frame containing the node (vertex) and link (edge) structure as well as the associated attributes for these. This provides an easy way to create data tables describing graphs, particularly helpful for users unfamiliar with the structure of igraph objects.

Usage

graphdf(x, ...)

# S4 method for class 'list'
graphdf(x, ...)

# S4 method for class 'goc'
graphdf(x, ...)

# S4 method for class 'grain'
graphdf(x, ...)

# S4 method for class 'mpg'
graphdf(x, ...)

# S4 method for class 'igraph'
graphdf(x, ...)

Arguments

x

A goc, mpg, igraph, or list object.

...

Additional arguments (not used).

Value

A list object containing:

v

node (vertex) names and associated attributes;

e

link (edge) lists and associated attributes.

Please see MPG() and GOC() for details about the attributes.

For GOC() objects which typically contain multiple thresholds, an enumerated list of the same length as the number of thresholds is returned each containing v and e elements.

See also

Author

Paul Galpern and Alex Chubaty

Examples

## Load raster landscape
tiny <- raster::raster(system.file("extdata/tiny.asc", package = "grainscape"))

## Create a resistance surface from a raster using an is-becomes reclassification
tinyCost <- raster::reclassify(tiny, rcl = cbind(c(1, 2, 3, 4), c(1, 5, 10, 12)))
## Produce a patch-based MPG where patches are resistance features=1
tinyPatchMPG <- MPG(cost = tinyCost, patch = tinyCost == 1)
## Extract a representative subset of 5 grains of connectivity
tinyPatchGOC <- GOC(tinyPatchMPG, nThresh = 5)
## Create a data.frame with the structure and attributes of a MPG object
tinyPatchMPG_df <- graphdf(tinyPatchMPG) # nolint

## Create a data.frame with the structure and attributes of a GOC object
tinyPatchGOC_df <- graphdf(tinyPatchGOC) # nolint

## Create a data.frame with the structure and attributes of any igraph object
graphdf(tinyPatchGOC@th[[1]]$goc)
#> [[1]]
#> [[1]]$v
#>    name polygonId centroidX centroidY polygonArea totalPatchArea
#> 1    25        25 21.164804 45.946927         179             14
#> 2    11        11 35.528302 76.175472         530            100
#> 3     2         2 24.097561 94.603659         164             30
#> 4     1         1  7.790323 93.129032         186             38
#> 5    33        33 76.029644 30.851779         253             21
#> 6    29        29 97.166667 41.371795          39              1
#> 7    10        10 96.060000 88.340000          25              2
#> 8     7         7 96.933333 94.683333          60              9
#> 9    27        27 39.861345 38.697479         476             76
#> 10   16        16 14.952381 70.563492         252             72
#> 11   15        15 22.877358 79.537736          53              7
#> 12   14        14 12.304688 81.367188         128             11
#> 13    3         3 42.166667 94.927083         192             46
#> 14    4         4 64.107143 90.910714         336             61
#> 15    5         5 72.312500 98.250000          16              1
#> 16   18        18 26.395522 57.385572         201             32
#> 17   38        38 56.521176 13.867059         425             31
#> 18   13        13  3.009804 80.705882         102              4
#> 19   30        30 18.108000 33.252000         250             32
#> 20   21        21 47.242424 58.886364         132              4
#> 21   28        28 83.831361 48.272189         338              4
#> 22    6         6 82.088123 85.595785         522             65
#> 23   20        20 37.360656 54.877049         122              5
#> 24   26        26  6.444134 43.768156         179              4
#> 25   36        36 85.342205 19.600760         526             55
#> 26   39        39 91.982587  6.067164         201             26
#> 27   22        22 60.739336 53.007109         422             39
#> 28   40        40 51.824675  3.058442          77              1
#> 29    9         9 52.510638 84.574468         188             14
#> 30   37        37 22.657810 12.435588         621             42
#> 31   34        34  5.820000 19.433333         375             18
#> 32   35        35 42.981481 23.084362         243             12
#> 33    8         8 19.357143 91.325397          63              7
#> 34   23        23 92.944795 58.755521         317              6
#> 35   31        31 60.324561 33.085965         285             15
#> 36   19        19  8.658451 58.595070         284              9
#> 37   41        41 64.756757  3.216216          74              2
#> 38   32        32 96.159091 33.090909          88              2
#> 39   24        24 73.349741 51.795337         193              4
#> 40   17        17 60.669856 71.672249         418              2
#> 41   12        12 93.478070 77.478070         228              4
#> 42   43        43 76.169643  4.223214         112              2
#> 43   42        42 36.820000  3.692000         125              2
#>    totalPatchEdgeArea totalCoreArea patchId
#> 1                  14             0      62
#> 2                  95             5      30
#> 3                  28             2       7
#> 4                  37             1       5
#> 5                  21             0      80
#> 6                   1             0      73
#> 7                   2             0      29
#> 8                   9             0      19
#> 9                  72             4      67
#> 10                 67             5      41
#> 11                  7             0      40
#> 12                 11             0      37
#> 13                 45             1       8
#> 14                 58             3       9
#> 15                  1             0      12
#> 16                 32             0      48
#> 17                 31             0      95
#> 18                  4             0      32
#> 19                 32             0      74
#> 20                  4             0      55
#> 21                  4             0      68
#> 22                 64             1      14
#> 23                  5             0      54
#> 24                  4             0      64
#> 25                 55             0      86
#> 26                 26             0     100
#> 27                 39             0      56
#> 28                  1             0     103
#> 29                 14             0      28
#> 30                 39             3      93
#> 31                 18             0      84
#> 32                 12             0      85
#> 33                  7             0      22
#> 34                  6             0      60
#> 35                 15             0      76
#> 36                  9             0      50
#> 37                  2             0     105
#> 38                  2             0      78
#> 39                  4             0      61
#> 40                  2             0      46
#> 41                  4             0      31
#> 42                  2             0     107
#> 43                  2             0     106
#> 
#> [[1]]$e
#>     e1 e2 maxWeight linkIdMaxWeight minWeight linkIdMinWeight medianWeight
#> 1   25 30        12               1        12               1           12
#> 2   11 16        12               2        12               2           12
#> 3   11 15        10               3        10               3           10
#> 4    2  8        10               4        10               4           10
#> 5    2  1         5               5         5               5            5
#> 6   33 36        10               6        10               6           10
#> 7   29 32        15               7        15               7           15
#> 8   10 12        10               8        10               8           10
#> 9   10  7        10               9        10               9           10
#> 10  27 35        20              10        20              10           20
#> 11  16 18        20              11        20              11           20
#> 12  16 15        20              12        20              12           20
#> 13  16 14        20              13        20              13           20
#> 14   3  9        25              14        25              14           25
#> 15   4  5        20              15        20              15           20
#> 16   5  6        30              16        30              16           30
#> 17  11 18        40              17        40              17           40
#> 18   3  4        32              18        32              18           32
#> 19  18 20        35              19        35              19           35
#> 20  38 40        40              20        40              20           40
#> 21  25 26        44              21        44              21           44
#> 22   1  8        40              22        40              22           40
#> 23  14 13        50              23        50              23           50
#> 24  30 34        40              24        40              24           40
#> 25  21 22        45              25        45              25           45
#> 26   1 13        45              26        45              26           45
#> 27   4  9        40              27        40              27           40
#> 28  33 28        45              28        45              28           45
#> 29   7  6        45              29        45              29           45
#> 30  11 20        50              30        50              30           50
#> 31   1 14        45              31        45              31           45
#> 32  21 20        50              32        50              32           50
#> 33  30 26        52              33        52              33           52
#> 34  36 39        55              34        55              34           55
#> 35  39 43        54              35        54              35           54
#> 36  16 19        55              36        55              36           55
#> 37  22 31        64              37        64              37           64
#> 38  22 24        59              38        59              38           59
#> 39  40 41        65              39        65              39           65
#> 40   4  6        60              40        60              40           60
#> 41  11  3        69              41        69              41           69
#> 42  38 41        75              42        75              42           75
#> 43  27 31        75              43        75              43           75
#> 44  27 21        75              44        75              44           75
#> 45  27 22        75              45        75              45           75
#> 46  10  6        75              46        75              46           75
#> 47   2  3        75              47        75              47           75
#> 48  30 37        80              48        80              48           80
#> 49   9 17        81              49        81              49           81
#> 50  15 14        80              50        80              50           80
#> 51  36 43        85              51        85              51           85
#> 52  37 42        85              52        85              52           85
#> 53  37 34        80              53        80              53           80
#> 54  11 21        85              54        85              54           85
#> 55  11  2        85              55        85              55           85
#> 56  38 35        85              56        85              56           85
#> 57   6 12        85              57        85              57           85
#> 58  14  8        85              58        85              58           85
#> 59   2 15        85              59        85              59           85
#> 60  29 23        88              60        88              60           88
#> 61  27 20        95              61        95              61           95
#> 62  35 31        95              62        95              62           95
#> 63  15  8        95              63        95              63           95
#> 64  26 19       105              64       105              64          105
#> 65  11  9       107              65       107              65          107
#> 66  41 43       105              66       105              66          105
#> 67  36 32       105              67       105              67          105
#> 68  16 13       100              68       100              68          100
#> 69  37 35       105              69       105              69          105
#> 70  11 17       105              70       105              70          105
#> 71  33 32       112              71       112              71          112
#> 72  28 32       114              72       114              72          114
#> 73  40 42       115              73       115              73          115
#> 74  38 37       115              74       115              74          115
#> 75  28 23       130              75       130              75          130
#> 76  29 28       129              76       129              76          129
#> 77  38 31       123              77       123              77          123
#> 78  28 24       123              78       123              78          123
#> 79  18 19       135              79       135              79          135
#> 80  26 34       125              80       125              80          125
#> 81  38 42       125              81       125              81          125
#> 82  25 19       130              82       130              82          130
#> 83  21 17       127              83       127              83          127
#> 84  22 17       132              84       132              84          132
#> 85  33 31       144              85       144              85          144
#> 86  27 30       151              86       151              86          151
#> 87  27 37       146              87       146              87          146
#> 88   4 17       140              88       140              88          140
#> 89  25 27       180              89       180              89          180
#> 90  23 12       162              90       162              90          162
#> 91  31 24       200              91       200              91          200
#> 92  33 24       210              92       210              92          210
#> 93  38 43       195              93       195              93          195
#> 94  33 38       201              94       201              94          201
#> 95  38 36       208              95       208              95          208
#> 96  27 18       210              96       210              96          210
#> 97   6 17       220              97       220              97          220
#> 98   6 23       290              98       290              98          290
#> 99  24 17       365              99       365              99          365
#> 100 28  6       358             100       358             100          358
#> 101  6 24       432             101       432             101          432
#>     meanWeight numEdgesWeight linkIdAll eucCentroidWeight
#> 1           12              1         1         13.057765
#> 2           12              1         2         21.327514
#> 3           10              1         3         13.090118
#> 4           10              1         4          5.763555
#> 5            5              1         5         16.373776
#> 6           10              1         6         14.605109
#> 7           15              1         7          8.341959
#> 8           10              1         8         11.164582
#> 9           10              1         9          6.403170
#> 10          20              1        10         15.921830
#> 11          20              1        11         17.452881
#> 12          20              1        12         11.972565
#> 13          20              1        13         11.123404
#> 14          25              1        14         14.634698
#> 15          20              1        15         11.008769
#> 16          30              1        16         15.990370
#> 17          40              1        17         20.891816
#> 18          32              1        18         22.305060
#> 19          35              1        19         11.248415
#> 20          40              1        20         11.784877
#> 21          44              1        21         14.881034
#> 22          40              1        22         11.706598
#> 23          50              1        23          9.318379
#> 24          40              1        24         18.491903
#> 25          45              1        25         14.721830
#> 26          45              1        26         13.311199
#> 27          40              1        27         13.214648
#> 28          45              1        28         19.087627
#> 29          45              1        29         17.405856
#> 30          50              1        30         21.377098
#> 31          45              1        31         12.598432
#> 32          50              1        32         10.664143
#> 33          52              1        33         15.704627
#> 34          55              1        34         15.074910
#> 35          54              1        35         15.920093
#> 36          55              1        36         13.522451
#> 37          64              1        37         19.925462
#> 38          59              1        38         12.668492
#> 39          65              1        39         12.933044
#> 40          60              1        40         18.750043
#> 41          69              1        41         19.891979
#> 42          75              1        42         13.463478
#> 43          75              1        43         21.218679
#> 44          75              1        44         21.495846
#> 45          75              1        45         25.311184
#> 46          75              1        46         14.238823
#> 47          75              1        47         18.072000
#> 48          80              1        48         21.307834
#> 49          81              1        49         15.265651
#> 50          80              1        50         10.729784
#> 51          85              1        51         17.905441
#> 52          85              1        52         16.643856
#> 53          80              1        53         18.234042
#> 54          85              1        54         20.883820
#> 55          85              1        55         21.685477
#> 56          85              1        56         16.379317
#> 57          85              1        57         13.986715
#> 58          85              1        58         12.202584
#> 59          85              1        59         15.115255
#> 60          88              1        60         17.889050
#> 61          95              1        61         16.371681
#> 62          95              1        62         20.020352
#> 63          95              1        63         12.302068
#> 64         105              1        64         14.991350
#> 65         107              1        65         18.945788
#> 66         105              1        66         11.457225
#> 67         105              1        67         17.291302
#> 68         100              1        68         15.668223
#> 69         105              1        69         22.944455
#> 70         105              1        70         25.541668
#> 71         112              1        71         20.253600
#> 72         114              1        72         19.556181
#> 73         115              1        73         15.018045
#> 74         115              1        74         33.893609
#> 75         130              1        75         13.890821
#> 76         129              1        76         15.014853
#> 77         123              1        77         19.591633
#> 78         123              1        78         11.057890
#> 79         135              1        79         17.778262
#> 80         125              1        80         24.342826
#> 81         125              1        81         22.173592
#> 82         130              1        82         17.787198
#> 83         127              1        83         18.541165
#> 84         132              1        84         18.665269
#> 85         144              1        85         15.863203
#> 86         151              1        86         22.424568
#> 87         146              1        87         31.395040
#> 88         140              1        88         19.543119
#> 89         180              1        89         20.052808
#> 90         162              1        90         18.730143
#> 91         200              1        91         22.796840
#> 92         210              1        92         21.114320
#> 93         195              1        93         21.887576
#> 94         201              1        94         25.866214
#> 95         208              1        95         29.385831
#> 96         210              1        96         23.034174
#> 97         220              1        97         25.546174
#> 98         290              1        98         28.952844
#> 99         365              1        99         23.576919
#> 100        358              1       100         37.364284
#> 101        432              1       101         34.911741
#> 
#>