如何在 R 中调整/控制树状图中的比例(使用“portfolio”库)?

发布于 2024-12-06 09:04:44 字数 124 浏览 0 评论 0原文

我正在使用 R 和“portfolio”库来构建树形图。比例默认为“-1000 到 1000”。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南汐寒笙箫 2024-12-13 09:04:44

零附近的对称颜色映射被硬编码到 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 参数仅影响绝对大小。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文