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 list
graphdf(x, ...)

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

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

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

# S4 method for 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   24        24 73.349741 51.795337         193              4
#> 39   17        17 60.669856 71.672249         418              2
#> 40   12        12 93.478070 77.478070         228              4
#> 41   32        32 96.159091 33.090909          88              2
#> 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                  4             0      61
#> 39                  2             0      46
#> 40                  4             0      31
#> 41                  2             0      78
#> 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 38 41        75              41        75              41           75
#> 42 27 31        75              42        75              42           75
#> 43 27 21        75              43        75              43           75
#> 44 27 22        75              44        75              44           75
#> 45 11  3        76              45        76              45           76
#> 46 10  6        75              46        75              46           75
#> 47 30 37        80              47        80              47           80
#> 48  2  3        70              48        70              48           70
#> 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 38 35        85              55        85              55           85
#> 56  6 12        85              56        85              56           85
#> 57 14  8        85              57        85              57           85
#> 58 29 23        88              58        88              58           88
#> 59 27 20        95              59        95              59           95
#> 60 35 31        95              60        95              60           95
#> 61 26 19       105              61       105              61          105
#> 62 11  9       107              62       107              62          107
#> 63 41 43       105              63       105              63          105
#> 64 16 13       100              64       100              64          100
#> 65 37 35       105              65       105              65          105
#> 66 11 17       100              66       100              66          100
#> 67 28 32       114              67       114              67          114
#> 68 40 42       115              68       115              68          115
#> 69 38 37       115              69       115              69          115
#> 70 28 23       130              70       130              70          130
#> 71 38 31       123              71       123              71          123
#> 72 29 28       129              72       129              72          129
#> 73 28 24       123              73       123              73          123
#> 74 18 19       135              74       135              74          135
#> 75 26 34       125              75       125              75          125
#> 76 38 42       125              76       125              76          125
#> 77 21 17       127              77       127              77          127
#> 78 22 17       132              78       132              78          132
#> 79 25 19       133              79       133              79          133
#> 80 33 31       144              80       144              80          144
#> 81 27 37       146              81       146              81          146
#> 82  4 17       140              82       140              82          140
#> 83 23 12       162              83       162              83          162
#> 84 31 24       200              84       200              84          200
#> 85 38 43       195              85       195              85          195
#> 86 33 38       208              86       208              86          208
#> 87 38 36       208              87       208              87          208
#> 88 33 24       210              88       210              88          210
#> 89  6 17       220              89       220              89          220
#> 90  6 23       290              90       290              90          290
#> 91 24 17       365              91       365              91          365
#> 92 28  6       358              92       358              92          358
#> 93  6 24       432              93       432              93          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         75              1        41         13.463478
#> 42         75              1        42         21.218679
#> 43         75              1        43         21.495846
#> 44         75              1        44         25.311184
#> 45         76              1        45         19.891979
#> 46         75              1        46         14.238823
#> 47         80              1        47         21.307834
#> 48         70              1        48         18.072000
#> 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         16.379317
#> 56         85              1        56         13.986715
#> 57         85              1        57         12.202584
#> 58         88              1        58         17.889050
#> 59         95              1        59         16.371681
#> 60         95              1        60         20.020352
#> 61        105              1        61         14.991350
#> 62        107              1        62         18.945788
#> 63        105              1        63         11.457225
#> 64        100              1        64         15.668223
#> 65        105              1        65         22.944455
#> 66        100              1        66         25.541668
#> 67        114              1        67         19.556181
#> 68        115              1        68         15.018045
#> 69        115              1        69         33.893609
#> 70        130              1        70         13.890821
#> 71        123              1        71         19.591633
#> 72        129              1        72         15.014853
#> 73        123              1        73         11.057890
#> 74        135              1        74         17.778262
#> 75        125              1        75         24.342826
#> 76        125              1        76         22.173592
#> 77        127              1        77         18.541165
#> 78        132              1        78         18.665269
#> 79        133              1        79         17.787198
#> 80        144              1        80         15.863203
#> 81        146              1        81         31.395040
#> 82        140              1        82         19.543119
#> 83        162              1        83         18.730143
#> 84        200              1        84         22.796840
#> 85        195              1        85         21.887576
#> 86        208              1        86         25.866214
#> 87        208              1        87         29.385831
#> 88        210              1        88         21.114320
#> 89        220              1        89         25.546174
#> 90        290              1        90         28.952844
#> 91        365              1        91         23.576919
#> 92        358              1        92         37.364284
#> 93        432              1        93         34.911741
#> 
#>