你如何在 R 中调整/控制树图中的比例(使用“投资组合"库)? [英] How do you adjust/control the scale in a treemap (using the 'portfolio' library) in R?

查看:47
本文介绍了你如何在 R 中调整/控制树图中的比例(使用“投资组合"库)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 R 和组合"库来构建树状图.比例默认为-1000 到 1000".

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

例如,我需要它是0 到 1000".我知道 map.market() 有一个scale"参数,但我不知道要传递给它什么.

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.

推荐答案

围绕零的对称颜色映射被硬编码到 map.market 中:

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
}

和,

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")))

注意 seq(-1,1,...) 语句的存在.scale 参数只影响绝对大小.

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

这篇关于你如何在 R 中调整/控制树图中的比例(使用“投资组合"库)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆