[BioC] PieGlyph - labels do not show

Florian Hahne fhahne at fhcrc.org
Fri Apr 17 01:37:54 CEST 2009


Hi Fraser,
I just added your fix to Rgraphviz. The idea of the user-defined glyph 
drawing functions is that people can draw whatever they want to, e.g. by 
extending already available functions, but since the pieGlyph 
documentation is advertising labels I agree that it should deliver...
Thanks for the patch,
Florian

Sim, Fraser wrote:
> I fixed the problem by referring to pie function and editing pieGlyphs
> accordingly.
>
> It's designed to draw lines +10% of the radius out for each label, and
> place the labels +20% from the center. It seems to works ok.
>
> Can we somehow add this to Rgraphviz?
>
> Fraser
>
> Here's my code:
>
> pieGlyph_new = function (x, xpos, ypos, labels = names(x), edges = 200,
> radius = 0.8, 
>     density = NULL, angle = 45, col = NULL, border = NULL, lty = NULL, 
>     main = NULL, ...) 
> {
>     if (!is.numeric(x) || any(is.na(x) | x <= 0)) 
>         stop("pie: `x' values must be positive.")
>     if (is.null(labels)) 
>         labels <- as.character(1:length(x))
>     x <- c(0, cumsum(x)/sum(x))
>     dx <- diff(x)
>     nx <- length(dx)
>     if (is.null(col)) 
>         col <- if (is.null(density)) 
>             c("lightblue", "mistyrose", "lightcyan", "lavender", 
>                 "cornsilk", "white")
>         else par("fg")
>     col <- rep(col, length.out = nx)
>     border <- rep(border, length.out = nx)
>     lty <- rep(lty, length.out = nx)
>     angle <- rep(angle, length.out = nx)
>     density <- rep(density, length.out = nx)
>     for (i in 1:nx) {
>         n <- max(2, floor(edges * dx[i]))
>         t2p <- 2 * pi * seq(x[i], x[i + 1], length = n)
>         xc <- c(cos(t2p), 0) * radius + xpos
>         yc <- c(sin(t2p), 0) * radius + ypos
>         polygon(xc, yc, density = density[i], angle = angle[i], 
>             border = border[i], col = col[i], lty = lty[i])
>
> # new code here        
>         t2p <- 2 * pi * mean(x[i + 0:1])
>         xc <- cos(t2p) * radius * c(1,1.1,1.2) + xpos
>         yc <- sin(t2p) * radius * c(1,1.1,1.2) + ypos
>         lab <- as.character(labels[i])
>         if (!is.na(lab) && nzchar(lab)) { 
>             lines(xc[1:2], yc[1:2])
>             text(xc[3], yc[3], labels[i], xpd = TRUE, 
>                  adj = ifelse(xc < xpos, 1, ifelse(xc == xpos, 0.5,
> 0)),...)
> 	  }
> # end new code
>
>     }
>     invisible(NULL)
> }
>
>
> -----Original Message-----
> From: bioconductor-bounces at stat.math.ethz.ch
> [mailto:bioconductor-bounces at stat.math.ethz.ch] On Behalf Of Sim, Fraser
> Sent: Thursday, April 16, 2009 4:09 PM
> To: bioconductor at stat.math.ethz.ch
> Subject: [BioC] PieGlyph - labels do not show
>
> Hi Robert,
>
> I'm working with RGraphViz to plot PieGlyphs and wanted to try and add
> labels to the pie slices.  The Usage page describes such a use.
>
> If I tried the following but no labels appear:
>
> library(Rgraphviz)
> plot(1:10, col="white")
> pieGlyph(1:2, 5, 5, labels = c("A","B") )
>
> ****************************************
> Also when I look at the function itself, it does look like it uses
> 'labels' at all. 
>
> function (x, xpos, ypos, labels = names(x), edges = 200, radius = 0.8, 
>     density = NULL, angle = 45, col = NULL, border = NULL, lty = NULL, 
>     main = NULL, ...) 
> {
>     if (!is.numeric(x) || any(is.na(x) | x <= 0)) 
>         stop("pie: `x' values must be positive.")
>     if (is.null(labels)) 
>         labels <- as.character(1:length(x))
>     x <- c(0, cumsum(x)/sum(x))
>     dx <- diff(x)
>     nx <- length(dx)
>     if (is.null(col)) 
>         col <- if (is.null(density)) 
>             c("lightblue", "mistyrose", "lightcyan", "lavender", 
>                 "cornsilk", "white")
>         else par("fg")
>     col <- rep(col, length.out = nx)
>     border <- rep(border, length.out = nx)
>     lty <- rep(lty, length.out = nx)
>     angle <- rep(angle, length.out = nx)
>     density <- rep(density, length.out = nx)
>     for (i in 1:nx) {
>         n <- max(2, floor(edges * dx[i]))
>         t2p <- 2 * pi * seq(x[i], x[i + 1], length = n)
>         xc <- c(cos(t2p), 0) * radius + xpos
>         yc <- c(sin(t2p), 0) * radius + ypos
>         polygon(xc, yc, density = density[i], angle = angle[i], 
>             border = border[i], col = col[i], lty = lty[i])
>     }
>     invisible(NULL)
> }
> <environment: namespace:Rgraphviz>
>
> ******************************************
>
> Here's my sessionInfo.
>
> R version 2.8.1 (2008-12-22) 
> i386-pc-mingw32 
>
> locale:
> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
> States.1252;LC_MONETARY=English_United
> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>
> attached base packages:
> [1] grid      stats     graphics  grDevices datasets  utils     tools
>
> [8] methods   base     
>
> other attached packages:
>  [1] org.Hs.eg.db_2.2.6   bioDist_1.14.0       gplots_2.6.0        
>  [4] gdata_2.4.2          gtools_2.5.0         limma_2.16.4        
>  [7] RColorBrewer_1.0-2   hgu133plus2.db_2.2.5 RSQLite_0.7-1       
> [10] DBI_0.2-4            AnnotationDbi_1.4.2  Rgraphviz_1.21.7    
> [13] graph_1.20.0         Biobase_2.2.1        rcom_2.0-4          
> [16] rscproxy_1.0-12     
>
> loaded via a namespace (and not attached):
>  [1] annotate_1.20.1   Category_2.8.2    cluster_1.11.12
> genefilter_1.22.0
>  [5] GSEABase_1.4.0    KEGGgraph_0.8.15  RBGL_1.18.0       ROC_1.16.0
>
>  [9] splines_2.8.1     survival_2.34-1   XML_1.99-0       
>
> Thanks,
> Fraser
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives:
> http://news.gmane.org/gmane.science.biology.informatics.conductor
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
>   


-- 
Florian Hahne, PhD
Computational Biology Program
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
PO Box 19024
Seattle, Washington 98109-1024
206-667-3148
fhahne at fhcrc.org



More information about the Bioconductor mailing list