@@ -61,7 +61,7 @@ layout_tbl_graph_hierarchy <- function(.data, center = NULL,
61
61
if (is.null(center )) {
62
62
thisRequiresBio(" Rgraphviz" )
63
63
prep <- as_matrix(.data , twomode = FALSE )
64
- if (anyDuplicated(rownames(prep ))){
64
+ if (anyDuplicated(rownames(prep ))) {
65
65
rownames(prep ) <- seq_len(nrow(prep ))
66
66
colnames(prep ) <- seq_len(ncol(prep ))
67
67
}
@@ -84,15 +84,13 @@ layout_tbl_graph_hierarchy <- function(.data, center = NULL,
84
84
Evt2 <- cbind(rep(2 , floor(ncol(net )/ 2 )), nrm(rng(floor(mm / 2 ))))
85
85
crd <- rbind(Act , Evt1 , Evt2 )
86
86
crd [which(is.nan(crd ))] <- 0.5
87
- crd [, 2 ] <- crd [, 2 ] * cos(pi ) - crd [, 1 ] * sin(pi )
88
87
rownames(crd ) <- c(dimnames(net )[[1 ]], dimnames(net )[[2 ]])
89
88
} else if (center == " events" ) {
90
89
Act1 <- cbind(rep(0 , ceiling(nrow(net )/ 2 )), nrm(rng(ceiling(nn / 2 ))))
91
90
Act2 <- cbind(rep(2 , floor(nrow(net )/ 2 )), nrm(rng(floor(nn / 2 ))))
92
91
Evt <- cbind(rep(1 , ncol(net )), nrm(rng(mm )))
93
92
crd <- rbind(Act1 , Act2 , Evt )
94
93
crd [which(is.nan(crd ))] <- 0.5
95
- crd [, 2 ] <- crd [, 2 ] * cos(pi ) - crd [, 1 ] * sin(pi )
96
94
rownames(crd ) <- c(dimnames(net )[[1 ]], dimnames(net )[[2 ]])
97
95
} else {
98
96
if (center %in% node_names(.data )) {
@@ -107,7 +105,6 @@ layout_tbl_graph_hierarchy <- function(.data, center = NULL,
107
105
}
108
106
crd <- rbind(side1 , side2 )
109
107
crd [which(is.nan(crd ))] <- 0.5
110
- crd [, 2 ] <- crd [, 2 ] * cos(pi ) - crd [, 1 ] * sin(pi )
111
108
rownames(crd ) <- c(dimnames(net )[[1 ]], dimnames(net )[[2 ]])
112
109
} else stop(" Please declare actors, events, or a node name as center." )
113
110
}
@@ -139,7 +136,7 @@ layout_tbl_graph_alluvial <- function(.data,
139
136
# ' @rdname partition_layouts
140
137
# ' @export
141
138
layout_tbl_graph_railway <- function (.data ,
142
- circular = FALSE , times = 1000 ){
139
+ circular = FALSE , times = 1000 ) {
143
140
res <- layout_tbl_graph_hierarchy(as_igraph(.data ))
144
141
res $ x <- c(match(res [res [,2 ]== 0 ,1 ], sort(res [res [,2 ]== 0 ,1 ])),
145
142
match(res [res [,2 ]== 1 ,1 ], sort(res [res [,2 ]== 1 ,1 ])))
@@ -239,52 +236,21 @@ layout_tbl_graph_lineage <- function(.data, rank, circular = FALSE) {
239
236
if (length(rank ) > 1 & length(rank ) != length(.data )) {
240
237
stop(" Please pass the function a `rank` node attribute or a vector." )
241
238
} else if (length(rank ) != length(.data )) {
242
- rank <- node_attribute(.data , rank )
243
- if (! is.numeric(rank ))
244
- stop(" Please declare a numeric attribute to `rank` nodes." )
239
+ rank <- as.numeric(node_attribute(.data , rank ))
245
240
}
246
241
thisRequiresBio(" Rgraphviz" )
247
- prep <- as_matrix(.data , twomode = FALSE )
248
- if (anyDuplicated(rownames(prep ))){
249
- rownames(prep ) <- seq_len(nrow(prep ))
250
- colnames(prep ) <- seq_len(ncol(prep ))
251
- }
252
- if (any(prep < 0 )) prep [prep < 0 ] <- 0
253
- out <- as_graphAM(prep )
254
- out <- suppressMessages(Rgraphviz :: layoutGraph(out , layoutType = ' dot' ,
255
- attrs = list (graph = list (rankdir = " BT" ))))
256
- nodeX <- .rescale(out @ renderInfo @ nodes $ nodeX )
257
- names <- names(nodeX )
258
- nodeY <- .rescale(rank * (- 1 ))
259
- .to_lo(.adjust(nodeX , nodeY , names ))
242
+ out <- layout_tbl_graph_alluvial(
243
+ as_igraph(mutate(.data , type = ifelse(
244
+ rank > mean(rank ), TRUE , FALSE )), twomode = TRUE ))
245
+ out $ x <- .rescale(rank )
246
+ .check_dup(out )
260
247
}
261
248
262
249
.rescale <- function (vector ){
263
250
(vector - min(vector )) / (max(vector ) - min(vector ))
264
251
}
265
252
266
- .adjust <- function (x , y , names ) {
267
- out <- data.frame (cbind(x , y , names ))
268
- adj <- data.frame ()
269
- for (k in levels(as.factor(y ))) {
270
- a <- subset(out , y == k )
271
- if (length(a [,1 ]) == 1 ) {
272
- a [,1 ] <- ifelse(a [,1 ] > 0.8 , as.numeric(a [,1 ])* 0.8 ,
273
- ifelse(a [,1 ] < 0.2 , as.numeric(a [,1 ])* 1.2 ,
274
- as.numeric(a [,1 ])))
275
- } else if (length(a [,1 ]) > 2 ) {
276
- a [,1 ] <- seq(min(a [,1 ]), max(a [,1 ]), len = length(a [,1 ]))
277
- }
278
- adj <- rbind(adj , a )
279
- }
280
- name <- data.frame (names = out [,3 ])
281
- out <- dplyr :: left_join(name , adj , by = " names" )
282
- out <- apply(out [,2 : 3 ], 2 , as.numeric )
283
- rownames(out ) <- name $ names
284
- out
285
- }
286
-
287
- .to_lo <- function (mat ){
253
+ .to_lo <- function (mat ) {
288
254
res <- as.data.frame(mat )
289
255
names(res ) <- c(" x" ," y" )
290
256
res
@@ -299,6 +265,11 @@ to_list <- function(members){
299
265
out
300
266
}
301
267
268
+ .check_dup <- function (mat ) {
269
+ mat $ y <- ifelse(duplicated(mat [c(' x' ,' y' )]), mat $ y * 0.95 , mat $ y )
270
+ mat
271
+ }
272
+
302
273
# ' @importFrom igraph degree
303
274
getNNvec <- function (.data , members ){
304
275
lapply(members , function (circle ){
0 commit comments