2

I am placing multiple treemaps inside their own viewport. I specify the viewport of certain size and then add the treemap to the viewport, however I can not get the treemap to fill the entire viewport.

Here is a sample code of what I am trying to do:

library(treemap)
library(grid)

main_vp <- viewport(x=0.5, y=0.5, width=1, height=1)
pushViewport(main_vp)

coords <- data.frame(X=c(0.2, 0.2, 0.5, 0.5), Y=c(0.2, 0.5, 0.5, 0.2))

for(i in 1:4)
{
  size <- 0.5
  my_x <- coords$X[i]
  my_y <- coords$Y[i]
  sub_vp <- viewport(x=my_x, y=my_y, width=size, height=size)
  pushViewport(sub_vp)
  grid.rect(gp=gpar(lty="dashed"), vp=main_vp)

  treemap(iris, index=c("Species"), vSize="Sepal.Length", vColor="Species", 
          title = "", vp=main_vp)

  upViewport()
  upViewport()
  upViewport()
}

If you execute the provided code, you will see that the treemap is very small with respect to the size of the sub viewport and I would like the treemap to cover the maximum area posible in the sub viewport. Any suggestions or examples, Thanks

enter image description here

4

1 回答 1

0

我试过你的示例代码

coords <- data.frame(X=c(0.25, 0.25, 0.75, 0.75), Y=c(0.25, 0.75, 0.75, 0.25))

size <- 0.4

生成的图像(从 RStudio 的绘图设备保存)是: 在此处输入图像描述

(固定)边距在这里似乎是正确的。

于 2013-09-19T19:42:30.020 回答