Skip to content

Commit f4d6eae

Browse files
committed
Merge branch 'dev'
2 parents 295bd4b + 2c42986 commit f4d6eae

File tree

9 files changed

+125
-99
lines changed

9 files changed

+125
-99
lines changed

DESCRIPTION

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ Description: This is a set of tools for dendrograms and
1616
functions that extract the dendrogram plot data. The package
1717
provides implementations for tree, rpart, as well as diana and agnes
1818
cluster diagrams.
19-
Version: 0.1-19
19+
Version: 0.1-20
2020
URL: https://github.com/andrie/ggdendro
2121
BugReports: https://github.com/andrie/ggdendro/issues
22-
Date: 2016-04-14
22+
Date: 2016-04-27
2323
Imports:
2424
MASS,
25-
ggplot2(>= 0.9.2),
26-
scales
25+
ggplot2(>= 0.9.2)
2726
Suggests:
2827
rpart(>= 4.0-0),
2928
tree,
3029
testthat,
3130
knitr,
32-
cluster
31+
cluster,
32+
scales
3333
VignetteBuilder: knitr
3434
RoxygenNote: 5.0.1

NEWS

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
1-
ggdendro 0.1-19 (Release date:)
1+
ggdendro 0.1-20 (Release date: 2016-04-27)
2+
==============
3+
4+
Functional changes:
5+
6+
- None
7+
8+
Enhancements:
9+
10+
- Don't open plot device during calculation of segment data #25
11+
12+
13+
ggdendro 0.1-19 (Release date: 2016-04-14)
214
==============
315

416
Functional changes:
517

618
- Removed margin argument from dendro_data.rpart, since this had no effect on plot.
719

20+
Bug fixes:
21+
22+
- Fixed issue 20: Plot data is dependent on device, causing errors and spurious new devices
23+
- Fixed issue 24: Labels don't print in `ggdendrogram()` with package `scales_0.4`
24+
- Fixed issue 22: Margin not working for `dendro_data.rpart`
25+
826

9-
ggdendro 0.1-18 (Release date: 25/2/2016)
27+
ggdendro 0.1-18 (Release date: 2016-02-25)
1028
==============
1129

1230
Functional changes:
@@ -17,8 +35,12 @@ Other changes:
1735

1836
- Minor change in documentation to comply with latest ggplot2 release
1937

38+
Fixes:
39+
40+
- Fixed issue 13 by adding `geom_blank()`
41+
2042

21-
ggdendro 0.1-17 (Release date: 6/9/2015)
43+
ggdendro 0.1-17 (Release date: 2015-09-06)
2244
==============
2345

2446
Fixes:
@@ -27,7 +49,7 @@ Fixes:
2749
- Update NAMESPACE to import functions from base R (required by R-devel)
2850

2951

30-
ggdendro 0.1-16 (Release date: 5/9/2015)
52+
ggdendro 0.1-16 (Release date: 2015-09-05)
3153
==============
3254

3355
New functionality:
@@ -49,7 +71,7 @@ Changes:
4971
- Modified vignette to use knitr instead of SWeave
5072

5173

52-
ggdendro 0.1-14 (Release date: 03/09/2013)
74+
ggdendro 0.1-14 (Release date: 2013-09-03)
5375
==============
5476

5577
New functionality
@@ -62,7 +84,7 @@ Changes:
6284

6385

6486

65-
ggdendro 0.1-12 (Release date: 27/01/2013)
87+
ggdendro 0.1-12 (Release date: 2013-01-27)
6688
==============
6789

6890
New functionality
@@ -72,7 +94,7 @@ Changes:
7294
* ggdendro now imports MASS, tree and ggplot2 (rather than suggests)
7395
* Added Brian D. Ripley as author (original author of package tree)
7496

75-
ggdendro 0.1-09 (Release date: 25/12/2012)
97+
ggdendro 0.1-09 (Release date: 2012-12-25)
7698
==============
7799

78100
New functionality
@@ -82,7 +104,7 @@ Changes:
82104
* Removed support for rpart
83105
* Changed Licence from GPL (>=2) to GPL-2|GPL-3 to conform with rtree license conditions
84106

85-
ggdendro 0.1-07 (Release date: 30/08/2012)
107+
ggdendro 0.1-07 (Release date: 2012-08-30)
86108
==============
87109

88110
New functionality
@@ -92,7 +114,7 @@ Changes:
92114
* Modified code to conform to `ggplot2` v0.9.2
93115

94116

95-
ggdendro 0.1-04 (Release date: 02/02/2012)
117+
ggdendro 0.1-04 (Release date: 2012-02-02)
96118
==============
97119

98120
New functionality
@@ -113,7 +135,7 @@ Changes in API
113135
* Fixed inconsistencies in the names of the `data.frame` segments. The names are now always `x`, `y`, `xend` and `yend`
114136

115137

116-
ggdendro 0.0-7 (Release date: 12/8/2011)
138+
ggdendro 0.0-7 (Release date: 2011-08-12)
117139
==============
118140

119141
New functionality

R/dendro_rpart.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ dendro_data.rpart <- function(model, uniform = FALSE, branch = 1, compress = FAL
5353

5454
if (compress & missing(nspace)) nspace <- branch
5555
if (!compress) nspace <- -1L # means no compression
56-
if(!interactive()) if (dev.cur() == 1L) dev.new() # not needed in R
56+
# if(!interactive()) if (dev.cur() == 1L) dev.new() # not needed in R
5757

5858
parms <- list(uniform = uniform,
5959
branch = branch,
6060
nspace = nspace,
6161
minbranch = minbranch)
6262

6363
## define the plot region
64-
temp <- rpartco(x, parms)
64+
temp <- rpartco(x, parms = parms)
6565
xx <- temp$x
6666
yy <- temp$y
6767
# temp1 <- range(xx) + diff(range(xx)) * c(-margin, margin)
6868
# temp2 <- range(yy) + diff(range(yy)) * c(-margin, margin)
6969
# plot(temp1, temp2, type = "n", axes = FALSE, xlab = "", ylab = "", ...)
7070
## Save information per device, once a new device is opened.
71-
assign(paste0("device", dev.cur()), parms, envir = rpart_ggdendro_env)
71+
# assign(paste0("device", dev.cur()), parms, envir = rpart_ggdendro_env)
7272

7373
# Draw a series of horseshoes or V's, left son, up, down to right son
7474
# NA's in the vector cause lines() to "lift the pen"

R/dendro_tree.R

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919

2020

21-
tree_ggdendro_env <- new.env()
21+
# tree_ggdendro_env <- new.env()
2222

2323
#' Extract data from regression tree object for plotting using ggplot.
2424
#'
@@ -43,14 +43,14 @@ dendro_data.tree <- function(model, type = c("proportional", "uniform"), ...){
4343
type <- match.arg(type)
4444
uniform <- type == "uniform"
4545

46-
dev <- dev.cur()
47-
if (dev == 1L) dev <- 2L # as device will be opened.
46+
# dev <- dev.cur()
47+
# if (dev == 1L) dev <- 2L # as device will be opened.
4848

49-
assign(paste0("device", dev), uniform, envir = tree_ggdendro_env)
49+
# assign(paste0("device", dev), uniform, envir = tree_ggdendro_env)
5050

51-
labels <- tree_labels(model, ...)
51+
labels <- tree_labels(model, uniform = uniform, ...)
5252
as.dendro(
53-
segments = tree_segments(model, ...),
53+
segments = tree_segments(model, uniform, ...),
5454
labels = labels$labels,
5555
leaf_labels = labels$leaf_labels,
5656
class="tree"
@@ -66,9 +66,10 @@ dendro_data.tree <- function(model, type = c("proportional", "uniform"), ...){
6666
#' @seealso \code{\link{ggdendrogram}}
6767
#' @family tree functions
6868
#' @author Code modified from original by Brian Ripley
69-
tree_segments <- function(model, ...){
69+
tree_segments <- function(model, uniform, ...){
70+
if(missing(uniform)) stop("specify the uniform argument")
7071
# Uses tree:::treeco to extract data frame of plot locations
71-
xy <- treeco(model)
72+
xy <- treeco(model, uniform = uniform)
7273
n <- model$frame$n
7374

7475
# Lines copied from tree:::treepl
@@ -92,9 +93,9 @@ tree_segments <- function(model, ...){
9293
#' @seealso \code{\link{ggdendrogram}}
9394
#' @family tree functions
9495
#' @author Code modified from original by Brian Ripley
95-
tree_labels <- function(model, ...){
96+
tree_labels <- function(model, uniform, ...){
9697
# Uses tree:::treeco to extract data frame of plot locations
97-
xy <- treeco(model)
98+
xy <- treeco(model, uniform = uniform)
9899
label <- model$frame$var
99100
yval <- model$frame$yval
100101
sleft <- model$frame$splits.cutleft
@@ -138,9 +139,9 @@ tree_labels <- function(model, ...){
138139
#' @seealso \code{\link{ggdendrogram}}
139140
#' @family tree functions
140141
#' @author Code modified from original by Brian Ripley
141-
get_data_tree_leaf_labels <- function(model, ...){
142+
get_data_tree_leaf_labels <- function(model, uniform, ...){
142143
# Uses tree:::treeco to extract data frame of plot locations
143-
xy <- treeco(model)
144+
xy <- treeco(model, uniform = uniform)
144145
label <- model$frame$var
145146
yval <- model$frame$yval
146147
sleft <- model$frame$splits.cutleft
@@ -167,14 +168,15 @@ get_data_tree_leaf_labels <- function(model, ...){
167168
#' @param tree tree object
168169
#' @param uniform ???
169170
#' @keywords internal
170-
treeco <- function (tree, uniform)
171-
{
172-
if (missing(uniform)) {
173-
pn <- paste0("device", dev.cur())
174-
uniform <- if (exists(pn, envir = tree_ggdendro_env, inherits = FALSE))
175-
get(pn, envir = tree_ggdendro_env, inherits = FALSE)
176-
else FALSE
177-
}
171+
treeco <- function (tree, uniform) {
172+
# if (missing(uniform)) {
173+
# pn <- paste0("device", dev.cur())
174+
# uniform <- if (exists(pn, envir = tree_ggdendro_env, inherits = FALSE))
175+
# get(pn, envir = tree_ggdendro_env, inherits = FALSE)
176+
# else FALSE
177+
# }
178+
if(missing(uniform)) stop("specify uniform argument")
179+
178180
frame <- tree$frame
179181
node <- as.integer(row.names(frame))
180182
depth <- tree.depth(node)

R/rpart.R

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -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
140140
rpart.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
180181
rpartco <- 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

Comments
 (0)