Hi, I have performed a clustering of a matrix and plotted the result with pltree. See code below. I want to color the labels of the leafs individually. For example I want the label name "Node 2" to be plotted in red. How do I do this? Sincerely Henrik library(cluster) D <- matrix(nr=4,nc=4) rownames(D) <- c("Node 1","Node 2","Node 3","Node 4") D[1,] <- c(0,.6,.1,.7) D[2,] <- c(.6,.0,.3,.9) D[3,] <- c(.1,.3,0,.9) D[4,] <- c(.7,.9,.9,0) C <- agnes(D,diss=T,method="complete") pltree(C) -- View this message in context: http://r.789695.n4.nabble.com/Color-individual-leaf-labels-in-dendrogram-tp2996982p2996982.html Sent from the R help mailing list archive at Nabble.com.
Dear List, I each iteration of a simulation study, I would like to save the p-value generated by "coxph". I fail to see how to adress the p-value. Do I have to calculate it myself from the Wald Test statistic? Cheers, Paddy
Henrik, there is an easily adaptable example in this thread: http://r.789695.n4.nabble.com/coloring-leaves-in-a-hclust-or-dendrogram-plot -tt795496.html#a795497 HTH. Bryan ************* Bryan Hanson Professor of Chemistry & Biochemistry DePauw University, Greencastle IN USA On 10/15/10 9:05 AM, "Kennedy" <henrik.aldberg at gmail.com> wrote:> > Hi, > > I have performed a clustering of a matrix and plotted the result with > pltree. See code below. I want to color the labels of the leafs > individually. For example I want the label name "Node 2" to be plotted in > red. How do I do this? > > Sincerely > > Henrik > > > library(cluster) > > D <- matrix(nr=4,nc=4) > rownames(D) <- c("Node 1","Node 2","Node 3","Node 4") > D[1,] <- c(0,.6,.1,.7) > D[2,] <- c(.6,.0,.3,.9) > D[3,] <- c(.1,.3,0,.9) > D[4,] <- c(.7,.9,.9,0) > > C <- agnes(D,diss=T,method="complete") > > pltree(C)
On Oct 15, 2010, at 9:21 AM, ?hagen Patrik wrote:> > Dear List, > > I each iteration of a simulation study, I would like to save the p- > value generated by "coxph". I fail to see how to adress the p-value. > Do I have to calculate it myself from the Wald Test statistic? >No. And the most important reason is that would not give you the same value as is print()-ed by coxph(). If you ask for the the str(print(coxph(...)) you get NULL (after the side-effect of prinitng. The print function only produces side- effects. On the other hand you can use the summary function and it gives you a richer set of output. Using the first example on the help page for coxph: str(summary(coxph(Surv(time, status) ~ x + strata(sex), test1))) List of 12 $ call : language coxph(formula = Surv(time, status) ~ x + strata(sex), data = test1) $ fail : NULL $ na.action : NULL $ n : int 7 $ loglik : num [1:2] -3.87 -3.33 $ coefficients: num [1, 1:5] 0.802 2.231 0.822 0.976 0.329 ..- attr(*, "dimnames")=List of 2 .. ..$ : chr "x" .. ..$ : chr [1:5] "coef" "exp(coef)" "se(coef)" "z" ... $ conf.int : num [1, 1:4] 2.231 0.448 0.445 11.18 ..- attr(*, "dimnames")=List of 2 .. ..$ : chr "x" .. ..$ : chr [1:4] "exp(coef)" "exp(-coef)" "lower .95" "upper .95" $ logtest : Named num [1:3] 1.087 1 0.297 ..- attr(*, "names")= chr [1:3] "test" "df" "pvalue" $ sctest : Named num [1:3] 1.051 1 0.305 ..- attr(*, "names")= chr [1:3] "test" "df" "pvalue" $ rsq : Named num [1:2] 0.144 0.669 ..- attr(*, "names")= chr [1:2] "rsq" "maxrsq" $ waldtest : Named num [1:3] 0.95 1 0.329 ..- attr(*, "names")= chr [1:3] "test" "df" "pvalue" $ used.robust : logi FALSE So the fifth element of coefficients leaf of the list structure has the same "p-value" as that print()-ed. Try: > summary(fit)$coefficients[5] [1] 0.3292583 (It does seem to me that the name for that leaf of the fit object is not particularly in accord with what I would have considered "coefficients"., but I am really in no solid position to criticize Terry Therneau to whom we all owe a great deal of gratitude.) -- David.
Thank you Brian, Your suggestion helped me a bit but I am not quite there yet. Now I have the following code: library(cluster) library(stats) D<-matrix(nr=4,nc=4) rownames(D)<-c("Node 1","Node 2","Node 3","Node 4") D[1,]<-c(0,.6,.1,.7) D[2,]<-c(.6,0,.3,.9) D[3,]<-c(.1,.3,0,.9) D[4,]<-c(.7,.9,.9,0) C<-agnes(D,diss=T,method="complete") DC<-as.dendrogram(C) # Function for coloring labels colLab <<- function(n){ if(is.leaf(n)){ a <- attributes(n) i <<- i+1 attr(n, "nodePar") <- c(a$nodePar, list(lab.col = mycol[i])) } n } # Define vector with label colors mycol<-vector(length=attributes(DC)$members) for(i in 1:attributes(DC)$members){ mycol[i]<-"black" } mycol[3]<-"red" i <- 0 dL <- dendrapply(DC, colLab) plot(dL) The remaining problems are: 1. I want to get rid of the little circles that are drawn at the end of each branch. 2. How do I access the original nodes. E.g. in the example above I set mycol[3]<-"red" which affects the third node in the tree which is Node 2. My intention was to paint the label "Node 3" in red. When the tree is larger this becomes a problem. Sincerely Henrik -- View this message in context: http://r.789695.n4.nabble.com/Color-individual-leaf-labels-in-dendrogram-tp2996982p2998322.html Sent from the R help mailing list archive at Nabble.com.