@@ -126,7 +126,7 @@ labels.rpart <- function(object, digits = 4, minlength = 1L, pretty,
126126
127127# rpart_ggdendro_env -------------------------------------------------------------------
128128
129- rpart_ggdendro_env <- new.env()
129+ # rpart_ggdendro_env <- new.env()
130130
131131
132132# rpart.branch ------------------------------------------------------------
@@ -139,13 +139,14 @@ rpart_ggdendro_env <- new.env()
139139# # most likely this could simply default to branch = 1
140140rpart.branch <- function (x , y , node , branch )
141141{
142- if (missing(branch )) {
143- pn <- paste0(" device" , dev.cur())
144- if (! exists(pn , envir = rpart_ggdendro_env , inherits = FALSE ))
145- stop(" no information available on parameters from previous call to plot()" )
146- parms <- get(pn , envir = rpart_ggdendro_env , inherits = FALSE )
147- branch <- parms $ branch
148- }
142+ # if (missing(branch)) {
143+ # pn <- paste0("device", dev.cur())
144+ # if (!exists(pn, envir = rpart_ggdendro_env, inherits = FALSE))
145+ # stop("no information available on parameters from previous call to plot()")
146+ # parms <- get(pn, envir = rpart_ggdendro_env, inherits = FALSE)
147+ # branch <- parms$branch
148+ # }
149+ if (missing(branch )) branch <- 1
149150
150151 # # Draw a series of horseshoes, left son, up, over, down to right son
151152 # # NA's in the vector cause lines() to "lift the pen"
@@ -179,12 +180,12 @@ tree.depth <- function (nodes)
179180# ' @keywords internal
180181rpartco <- function (tree , parms )
181182{
182- if (missing(parms )) {
183- pn <- paste0(" device" , dev.cur())
184- if (! exists(pn , envir = rpart_ggdendro_env , inherits = FALSE ))
185- stop(" no information available on parameters from previous call to plot()" )
186- parms <- get(pn , envir = rpart_ggdendro_env , inherits = FALSE )
187- }
183+ # if (missing(parms)) {
184+ # pn <- paste0("device", dev.cur())
185+ # if (!exists(pn, envir = rpart_ggdendro_env, inherits = FALSE))
186+ # stop("no information available on parameters from previous call to plot()")
187+ # parms <- get(pn, envir = rpart_ggdendro_env, inherits = FALSE)
188+ # }
188189
189190 frame <- tree $ frame
190191 node <- as.numeric(row.names(frame ))
@@ -204,7 +205,7 @@ rpartco <- function(tree, parms)
204205 y <- (1 + max(depth ) - depth ) / max(depth , 4L )
205206 else { # make y- (parent y) = change in deviance
206207 y <- dev <- frame $ dev
207- temp <- split(seq(node ), depth ) # d epth 0 nodes, then 1, then ...
208+ temp <- split(seq(node ), depth ) # depth 0 nodes, then 1, then ...
208209 parent <- match(node %/% 2L , node )
209210 sibling <- match(ifelse(node %% 2L , node - 1L , node + 1L ), node )
210211
@@ -337,7 +338,8 @@ text.rpart <- function(x, splits = TRUE, label, FUN = text, all = FALSE,
337338 col <- names(frame )
338339 ylevels <- attr(x , " ylevels" )
339340 if (! is.null(ylevels <- attr(x , " ylevels" ))) col <- c(col , ylevels )
340- cxy <- par(" cxy" ) # character width and height
341+ # cxy <- par("cxy") # character width and height
342+ cxy <- c(0.1 , 0.1 )
341343 if (! is.null(srt <- list (... )$ srt ) && srt == 90 ) cxy <- rev(cxy )
342344 xy <- rpartco(x , parms = parms )
343345
@@ -386,41 +388,41 @@ text.rpart <- function(x, splits = TRUE, label, FUN = text, all = FALSE,
386388 ylevel = ylevels , digits = digits ,
387389 n = frame $ n [leaves ], use.n = use.n )
388390
389- if (fancy ) {
390- if (col2rgb(bg , alpha = TRUE )[4L , 1L ] < 255 ) bg <- " white"
391- oval <- function (middlex , middley , a , b )
392- {
393- theta <- seq(0 , 2 * pi , pi / 30 )
394- newx <- middlex + a * cos(theta )
395- newy <- middley + b * sin(theta )
396- polygon(newx , newy , border = TRUE , col = bg )
397- }
398-
399- # # FIXME: use rect()
400- rectangle <- function (middlex , middley , a , b )
401- {
402- newx <- middlex + c(a , a , - a , - a )
403- newy <- middley + c(b , - b , - b , b )
404- polygon(newx , newy , border = TRUE , col = bg )
405- }
406-
407- # # find maximum length of stat
408- maxlen <- max(string.bounding.box(stat )$ columns ) + 1L
409- maxht <- max(string.bounding.box(stat )$ rows ) + 1L
410-
411- a.length <- if (fwidth < 1 ) fwidth * cxy [1L ] * maxlen else fwidth * cxy [1L ]
412-
413- b.length <- if (fheight < 1 ) fheight * cxy [2L ] * maxht else fheight * cxy [2L ]
414-
415- # # create ovals and rectangles here
416- # # sqrt(2) creates the smallest oval that fits around the
417- # # best fitting rectangle
418- for (i in parent )
419- oval(xy $ x [i ], xy $ y [i ], sqrt(2 ) * a.length / 2 , sqrt(2 ) * b.length / 2 )
420- child <- match(node [frame $ var == " <leaf>" ], node )
421- for (i in child )
422- rectangle(xy $ x [i ], xy $ y [i ], a.length / 2 , b.length / 2 )
423- }
391+ # if (fancy) {
392+ # if (col2rgb(bg, alpha = TRUE)[4L, 1L] < 255) bg <- "white"
393+ # oval <- function(middlex, middley, a, b)
394+ # {
395+ # theta <- seq(0, 2 * pi, pi/30)
396+ # newx <- middlex + a * cos(theta)
397+ # newy <- middley + b * sin(theta)
398+ # polygon(newx, newy, border = TRUE, col = bg)
399+ # }
400+ #
401+ # ## FIXME: use rect()
402+ # rectangle <- function(middlex, middley, a, b)
403+ # {
404+ # newx <- middlex + c(a, a, -a, -a)
405+ # newy <- middley + c(b, -b, -b, b)
406+ # polygon(newx, newy, border = TRUE, col = bg)
407+ # }
408+ #
409+ # ## find maximum length of stat
410+ # maxlen <- max(string.bounding.box(stat)$columns) + 1L
411+ # maxht <- max(string.bounding.box(stat)$rows) + 1L
412+ #
413+ # a.length <- if (fwidth < 1) fwidth * cxy[1L] * maxlen else fwidth * cxy[1L]
414+ #
415+ # b.length <- if (fheight < 1) fheight * cxy[2L] * maxht else fheight * cxy[2L]
416+ #
417+ # ## create ovals and rectangles here
418+ # ## sqrt(2) creates the smallest oval that fits around the
419+ # ## best fitting rectangle
420+ # for (i in parent)
421+ # oval(xy$x[i], xy$y[i], sqrt(2) * a.length/2, sqrt(2) * b.length/2)
422+ # child <- match(node[frame$var == "<leaf>"], node)
423+ # for (i in child)
424+ # rectangle(xy$x[i], xy$y[i], a.length/2, b.length/2)
425+ # }
424426
425427 # #if FUN=text then adj=1 puts the split label to the left of the
426428 # # split rather than centered
0 commit comments