单个页面上的多个 R 树图缩放 [英] Multiple R treemaps on a single page with scaling

查看:50
本文介绍了单个页面上的多个 R 树图缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在一个页面上放置多个树状图.每个树图都是数据的一个子集,一次查看它们会很有用.以下代码为每个子集创建了一个树状图,但它们每个都在自己的页面上.

I'm trying to put multiple treemaps on a single page. Each tree map is for a subset of the data and it would be useful to see them all at once. The following code creates a treemap for each subset but they each are on their own page.

问题 1) 有没有办法将所有树状图放在一页上?问题 2) 有没有办法缩放每个树状图的整体大小,使一些更大一些更小一些?

Question 1) Is there a way to put all of the treemaps on one page? Question 2) Is there a way to scale the overall size each treemap making some larger and some smaller?

library(treemap)
library(plyr)

numSubsets = sapply(df[myIndexColumn], function(x) length(unique(x)))
par(mfrow=c(1, numSubsets))
do_treemap <- function(mySubset)
{

  t <- paste("Subset Number",mySubset$subset_num[1])
  treemap(mySubset, index=c("Level 1","Level 2"), vSize="sizeVar", vColor="colorVar", title=t)
}

ddply(df, .variables=c("subset_num"), .fun=do_treemap)

推荐答案

treemap 函数接受一个vp"参数,它是一个网格视口.

the treemap function accepts a "vp" argument which is a grid viewport.

grid.newpage()
grid.rect()
pushViewport(viewport(layout=grid.layout(3, 1)))


do_treemap <- function(ind){
    vp <- viewport(layout.pos.col=1, layout.pos.row=ind)
    pushViewport(vp)
    treemap(business, index=c("NACE1", "NACE2", "NACE3"), vSize="turnover", type="index",vp=vp)
    popViewport()
    popViewport() #treemap doees not seem to pop corretly
    popViewport() #and one more!
}

lapply(1:3, do_treemap)

这篇关于单个页面上的多个 R 树图缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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