Produce a data.frame containing the structure and associated attributes
Source: R/graphdf.R
graphdf.RdProduce 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, ...)Value
A list object containing:
vnode (vertex) names and associated attributes;
elink (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.
Examples
## Load raster landscape
tiny <- terra::rast(
system.file("extdata", "tiny.asc", package = "grainscape", mustWork = TRUE)
)
## Create a resistance surface from a raster using an is-becomes reclassification
tinyCost <- terra::classify(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)
## Create a data.frame with the structure and attributes of a GOC object
tinyPatchGOC_df <- graphdf(tinyPatchGOC)
## 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 33 33 76.154321 31.170782 243 21
#> 2 11 11 35.437143 76.460000 525 100
#> 3 10 10 95.571429 88.357143 28 2
#> 4 7 7 96.877049 94.647541 61 9
#> 5 2 2 24.097561 94.603659 164 30
#> 6 1 1 7.790323 93.129032 186 38
#> 7 29 29 97.125000 41.475000 40 1
#> 8 16 16 14.956349 70.646825 252 72
#> 9 14 14 12.293651 81.365079 126 11
#> 10 27 27 39.936590 38.747401 481 76
#> 11 15 15 22.877358 79.537736 53 7
#> 12 4 4 64.132047 90.927300 337 61
#> 13 25 25 21.031792 46.170520 173 14
#> 14 3 3 42.293651 94.960317 189 46
#> 15 5 5 72.214286 98.571429 14 1
#> 16 38 38 56.481132 13.938679 424 31
#> 17 30 30 18.274704 33.416996 253 32
#> 18 21 21 47.188889 59.159259 135 4
#> 19 18 18 26.386700 57.421182 203 32
#> 20 6 6 81.964217 85.583172 517 65
#> 21 13 13 3.043689 80.713592 103 4
#> 22 20 20 37.444444 55.119048 126 5
#> 23 28 28 83.831361 48.272189 338 4
#> 24 26 26 6.444134 43.768156 179 4
#> 25 39 39 92.042714 6.057789 199 26
#> 26 36 36 85.129907 19.625234 535 55
#> 27 22 22 60.812649 53.094272 419 39
#> 28 40 40 52.006329 3.094937 79 1
#> 29 37 37 22.579545 12.465909 616 42
#> 30 34 34 5.867725 19.441799 378 18
#> 31 9 9 52.483957 84.596257 187 14
#> 32 23 23 92.936709 58.797468 316 6
#> 33 35 35 42.973029 23.147303 241 12
#> 34 8 8 19.357143 91.325397 63 7
#> 35 32 32 96.162921 33.028090 89 2
#> 36 41 41 64.756757 3.216216 74 2
#> 37 19 19 8.658451 58.595070 284 9
#> 38 24 24 73.383598 51.611111 189 4
#> 39 31 31 60.343206 33.088850 287 15
#> 40 17 17 60.785036 71.659145 421 2
#> 41 12 12 93.447826 77.552174 230 4
#> 42 43 43 76.234513 4.216814 113 2
#> 43 42 42 36.907692 3.884615 130 2
#> totalPatchEdgeArea totalCoreArea patchId
#> 1 21 0 80
#> 2 95 5 30
#> 3 2 0 29
#> 4 9 0 19
#> 5 28 2 7
#> 6 37 1 5
#> 7 1 0 73
#> 8 67 5 41
#> 9 11 0 37
#> 10 72 4 67
#> 11 7 0 40
#> 12 58 3 9
#> 13 14 0 62
#> 14 45 1 8
#> 15 1 0 12
#> 16 31 0 95
#> 17 32 0 74
#> 18 4 0 55
#> 19 32 0 48
#> 20 64 1 14
#> 21 4 0 32
#> 22 5 0 54
#> 23 4 0 68
#> 24 4 0 64
#> 25 26 0 100
#> 26 55 0 86
#> 27 39 0 56
#> 28 1 0 103
#> 29 39 3 93
#> 30 18 0 84
#> 31 14 0 28
#> 32 6 0 60
#> 33 12 0 85
#> 34 7 0 22
#> 35 2 0 78
#> 36 2 0 105
#> 37 9 0 50
#> 38 4 0 61
#> 39 15 0 76
#> 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 33 36 10 1 10 1 10
#> 2 11 15 10 2 10 2 10
#> 3 10 12 10 3 10 3 10
#> 4 10 7 10 4 10 4 10
#> 5 2 8 5 5 5 5 5
#> 6 2 1 5 6 5 6 5
#> 7 29 32 15 7 15 7 15
#> 8 16 18 20 8 20 8 20
#> 9 11 16 12 9 12 9 12
#> 10 16 14 20 10 20 10 20
#> 11 27 35 20 11 20 11 20
#> 12 16 15 20 12 20 12 20
#> 13 4 5 20 13 20 13 20
#> 14 25 30 12 14 12 14 12
#> 15 3 9 25 15 25 15 25
#> 16 5 6 30 16 30 16 30
#> 17 4 3 32 17 32 17 32
#> 18 38 40 40 18 40 18 40
#> 19 30 34 40 19 40 19 40
#> 20 21 22 40 20 40 20 40
#> 21 18 20 35 21 35 21 35
#> 22 1 13 40 22 40 22 40
#> 23 4 9 40 23 40 23 40
#> 24 7 6 40 24 40 24 40
#> 25 25 26 44 25 44 25 44
#> 26 14 13 45 26 45 26 45
#> 27 21 20 50 27 50 27 50
#> 28 11 20 45 28 45 28 45
#> 29 33 28 45 29 45 29 45
#> 30 1 14 45 30 45 30 45
#> 31 30 26 52 31 52 31 52
#> 32 39 43 54 32 54 32 54
#> 33 16 19 55 33 55 33 55
#> 34 39 36 55 34 55 34 55
#> 35 22 31 60 35 60 35 60
#> 36 22 24 59 36 59 36 59
#> 37 40 41 65 37 65 37 65
#> 38 27 31 70 38 70 38 70
#> 39 11 3 69 39 69 39 69
#> 40 2 3 70 40 70 40 70
#> 41 38 41 80 41 80 41 80
#> 42 27 21 75 42 75 42 75
#> 43 37 42 80 43 80 43 80
#> 44 30 37 77 44 77 44 77
#> 45 37 34 80 45 80 45 80
#> 46 27 22 75 46 75 46 75
#> 47 11 2 80 47 80 47 80
#> 48 9 17 81 48 81 48 81
#> 49 29 23 88 49 88 49 88
#> 50 2 15 85 50 85 50 85
#> 51 38 35 85 51 85 51 85
#> 52 36 43 85 52 85 52 85
#> 53 11 21 85 53 85 53 85
#> 54 14 8 85 54 85 54 85
#> 55 6 12 85 55 85 55 85
#> 56 27 20 95 56 95 56 95
#> 57 36 32 100 57 100 57 100
#> 58 11 17 100 58 100 58 100
#> 59 41 43 105 59 105 59 105
#> 60 37 35 105 60 105 60 105
#> 61 26 19 105 61 105 61 105
#> 62 28 32 114 62 114 62 114
#> 63 40 42 115 63 115 63 115
#> 64 38 37 115 64 115 64 115
#> 65 28 24 123 65 123 65 123
#> 66 38 31 123 66 123 66 123
#> 67 29 28 129 67 129 67 129
#> 68 25 19 130 68 130 68 130
#> 69 22 17 132 69 132 69 132
#> 70 38 42 125 70 125 70 125
#> 71 21 17 125 71 125 71 125
#> 72 33 31 144 72 144 72 144
#> 73 28 23 130 73 130 73 130
#> 74 27 30 149 74 149 74 149
#> 75 23 12 162 75 162 75 162
#> 76 25 18 192 76 192 76 192
#> 77 38 36 201 77 201 77 201
#> 78 33 38 208 78 208 78 208
#> 79 6 17 220 79 220 79 220
#> 80 6 28 358 80 358 80 358
#> 81 6 24 432 81 432 81 432
#> meanWeight numEdgesWeight linkIdAll eucCentroidWeight
#> 1 10 1 1 14.623981
#> 2 10 1 2 12.931382
#> 3 10 1 3 11.011678
#> 4 10 1 4 6.424465
#> 5 5 1 5 5.763555
#> 6 5 1 6 16.373776
#> 7 15 1 7 8.501523
#> 8 20 1 8 17.480576
#> 9 12 1 9 21.289808
#> 10 20 1 10 11.044045
#> 11 20 1 11 15.892861
#> 12 20 1 12 11.907589
#> 13 20 1 13 11.124535
#> 14 12 1 14 13.048138
#> 15 25 1 15 14.534652
#> 16 30 1 16 16.240565
#> 17 32 1 17 22.207674
#> 18 40 1 18 11.730755
#> 19 40 1 19 18.687944
#> 20 40 1 20 14.912777
#> 21 35 1 21 11.294846
#> 22 40 1 22 13.291865
#> 23 40 1 23 13.257455
#> 24 40 1 24 17.451514
#> 25 44 1 25 14.784151
#> 26 45 1 26 9.272876
#> 27 50 1 27 10.548815
#> 28 45 1 28 21.435147
#> 29 45 1 29 18.745535
#> 30 45 1 30 12.596450
#> 31 52 1 31 15.719698
#> 32 54 1 32 15.915036
#> 33 55 1 33 13.598100
#> 34 55 1 34 15.227030
#> 35 60 1 35 20.010929
#> 36 59 1 36 12.658140
#> 37 65 1 37 12.751004
#> 38 70 1 38 21.176618
#> 39 69 1 39 19.730014
#> 40 70 1 40 18.199585
#> 41 80 1 41 13.544636
#> 42 75 1 42 21.661943
#> 43 80 1 43 16.701329
#> 44 77 1 44 21.388775
#> 45 80 1 45 18.109334
#> 46 75 1 46 25.330664
#> 47 80 1 47 21.395758
#> 48 81 1 48 15.371297
#> 49 88 1 49 17.821607
#> 50 85 1 50 15.115255
#> 51 85 1 51 16.348321
#> 52 85 1 52 17.791779
#> 53 85 1 53 20.914568
#> 54 85 1 54 12.210686
#> 55 85 1 55 14.013216
#> 56 95 1 56 16.560241
#> 57 100 1 57 17.359838
#> 58 100 1 58 25.798525
#> 59 105 1 59 11.521289
#> 60 105 1 60 23.021432
#> 61 105 1 61 14.991350
#> 62 114 1 62 19.607395
#> 63 115 1 63 15.119273
#> 64 115 1 64 33.933562
#> 65 123 1 65 10.968325
#> 66 123 1 66 19.535728
#> 67 129 1 67 14.930594
#> 68 130 1 68 17.534795
#> 69 132 1 69 18.564893
#> 70 125 1 70 22.004630
#> 71 125 1 71 18.468956
#> 72 144 1 72 15.927032
#> 73 130 1 73 13.917214
#> 74 149 1 74 22.308083
#> 75 162 1 75 18.761669
#> 76 192 1 76 12.460033
#> 77 201 1 77 29.207690
#> 78 208 1 78 26.153006
#> 79 220 1 79 25.346326
#> 80 358 1 80 37.357672
#> 81 432 1 81 35.038949
#>
#>