5

I am using R and the 'portfolio' library to build a treemap. The scale is defaulting to '-1000 to 1000'.

I need it to be '0 to 1000', for example. I know there is a 'scale' parameter to map.market(), but I can't figure out what to pass to it.

NJ.
  • 2,155
  • 6
  • 26
  • 35

1 Answers1

3

A symmetric colour-mapping around zero is hard coded into map.market:

legend.ncols <- 51
l.x <- (0:(legend.ncols - 1))/(legend.ncols)
l.y <- unit(0.25, "npc")
l.cols <- color.ramp.rgb(seq(-1, 1, by = 2/(legend.ncols - 
    1)))
if (is.null(scale)) {
    l.end <- max(abs(data$color.orig))
}
else {
    l.end <- scale
}

and,

top.list <- gList(textGrob(label = main, y = unit(0.7, "npc"), 
    just = c("center", "center"), gp = gpar(cex = 2)), segmentsGrob(x0 = seq(0, 
    1, by = 0.25), y0 = unit(0.25, "npc"), x1 = seq(0, 1, 
    by = 0.25), y1 = unit(0.2, "npc")), rectGrob(x = l.x, 
    y = l.y, width = 1/legend.ncols, height = unit(1, "lines"), 
    just = c("left", "bottom"), gp = gpar(col = NA, fill = l.cols), 
    default.units = "npc"), textGrob(label = format(l.end * 
    seq(-1, 1, by = 0.5), trim = TRUE), x = seq(0, 1, by = 0.25), 
    y = 0.1, default.units = "npc", just = c("center", "center"), 
    gp = gpar(col = "black", cex = 0.8, fontface = "bold")))

Note the presence of seq(-1,1,...) statements. The scale parameter only affects the absolute size.

James
  • 65,548
  • 14
  • 155
  • 193
  • 1
    Just to clarify for those who, like me, didn't understand what to do with the above hint: type "map.market" in the R console, copy the output and rewrite the place `seq(-1, 1` with what you need. Then just paste this function in your code and run it, instead of original `map.market()`. Other parameters can be changed as well. – Anton Tarasenko Dec 07 '13 at 11:17