clone the plot environment before assigning layout
... | ... |
@@ -15,6 +15,7 @@ |
15 | 15 |
rotate_tree <- function(treeview, angle) { |
16 | 16 |
treeview <- treeview + coord_polar(theta='y', start=(angle-90)/180*pi, -1) |
17 | 17 |
treeview$data$angle <- treeview$data$angle + angle |
18 |
+ treeview$plot_env <- build_new_plot_env(treeview$plot_env) |
|
18 | 19 |
assign("layout", "circular", envir = treeview$plot_env) |
19 | 20 |
return(treeview) |
20 | 21 |
} |
... | ... |
@@ -46,6 +47,7 @@ open_tree <- function(treeview, angle) { |
46 | 47 |
angle <- 360/(2+NN) * (1:N+1) |
47 | 48 |
angle <- angle[idx] |
48 | 49 |
p$data$angle <- angle |
50 |
+ p$plot_env <- build_new_plot_env(p$plot_env) |
|
49 | 51 |
assign("layout", "fan", envir = p$plot_env) |
50 | 52 |
return(p) |
51 | 53 |
} |
... | ... |
@@ -115,8 +115,10 @@ ggplot_add.layout_ggtree <- function(object, plot, object_name) { |
115 | 115 |
} else { ## rectangular |
116 | 116 |
obj <- coord_cartesian(clip = 'off') |
117 | 117 |
} |
118 |
+ plot <- ggplot_add(obj, plot, object_name) |
|
119 |
+ plot$plot_env <- build_new_plot_env(plot$plot_env) |
|
118 | 120 |
assign("layout", object$layout, envir = plot$plot_env) |
119 |
- ggplot_add(obj, plot, object_name) |
|
121 |
+ return(plot) |
|
120 | 122 |
} |
121 | 123 |
|
122 | 124 |
|
... | ... |
@@ -17,6 +17,18 @@ get_layout <- function(tree_view = NULL) { |
17 | 17 |
return(layout) |
18 | 18 |
} |
19 | 19 |
|
20 |
+build_new_plot_env <- function(env){ |
|
21 |
+ newenv <- list2env( |
|
22 |
+ x = as.list( |
|
23 |
+ env, |
|
24 |
+ all.names = TRUE |
|
25 |
+ ), |
|
26 |
+ parent = parent.env(env) |
|
27 |
+ ) |
|
28 |
+ attributes(newenv) <- attributes(env) |
|
29 |
+ return(newenv) |
|
30 |
+} |
|
31 |
+ |
|
20 | 32 |
reverse.treeview <- function(tv) { |
21 | 33 |
tv$data <- reverse.treeview.data(tv$data) |
22 | 34 |
return(tv) |