Browse code

Merge pull request #506 from LPDagallier/branch-1

Add outline to nodepies

Guangchuang Yu authored on 20/06/2022 06:40:02 • GitHub committed on 20/06/2022 06:40:02
Showing2 changed files

... ...
@@ -119,7 +119,7 @@ nodebar <- function(data, cols, color, alpha=1, position="stack") {
119 119
 ##' @return list of ggplot objects
120 120
 ##' @export
121 121
 ##' @author Guangchuang Yu
122
-nodepie <- function(data, cols, color, alpha=1) {
122
+nodepie <- function(data, cols, color, alpha=1, outline.color="transparent", outline.size=0) {
123 123
     if (! "node" %in% colnames(data)) {
124 124
         stop("data should have a column 'node'...")
125 125
     }
... ...
@@ -128,14 +128,14 @@ nodepie <- function(data, cols, color, alpha=1) {
128 128
         color <- NA
129 129
     }
130 130
     ldf <- gather(data, type, value, !! cols) %>% split(., .$node)
131
-    lapply(ldf, function(df) ggpie(df, y=~value, fill=~type, color, alpha))
131
+    lapply(ldf, function(df) ggpie(df, y=~value, fill=~type, color, alpha, outline.color, outline.size))
132 132
 }
133 133
 
134 134
 
135 135
 ##' @importFrom methods missingArg
136
-ggpie <- function(data, y, fill, color, alpha=1) {
136
+ggpie <- function(data, y, fill, color, alpha=1, outline.color="transparent", outline.size=0) {
137 137
     p <- ggplot(data, aes_(x=1, y=y, fill=fill)) +
138
-        geom_bar(stat='identity', alpha=alpha) +
138
+        geom_bar(stat='identity', alpha=alpha, color=outline.color, size=outline.size, show.legend = F) +
139 139
         coord_polar(theta='y') + theme_inset()
140 140
 
141 141
     if (missingArg(color) || is.null(color) || is.na(color)) {
... ...
@@ -121,7 +121,7 @@ theme_tree2_internal <- function(bgcolor="white", fgcolor="black",
121 121
 theme_inset <- function(legend.position =  "none", ...) {
122 122
     list(xlab(NULL),
123 123
          ylab(NULL),
124
-         theme_tree(legend.position = legend.position, ...),
124
+         theme_tree(legend.position = legend.position, plot.margin = unit(c(0, 0, 0, 0), "lines"), ...),
125 125
          ggfun::theme_transparent()
126 126
          )
127 127
 }