I use the package ( treemap ), which uses the grid package to create the treemap. However, I would like to build several of these treemaps together to add different color schemes to these graphs. The tmPlot function uses the grid.newpage function, which clears the graphics window. I have not found a way to save grid.newpage objects, as you can do for ggplot2 objects. Is there a way to build multiple grid.newpage objects in one window?
## Example library(treemap) # load Gross national income data data(GNI2010) size <- aggregate(GNI ~ continent, GNI2010, sum) size <- size[with(size, order(GNI, decreasing = T)),] cont <- size$continent widths <- c(sum(size[c(1,3,5),]$GNI), sum(size$GNI) - sum(size[c(1,3,5),]$GNI)) heights <- c(sum(size[c(1,2),]$GNI), sum(size[c(3,4),]$GNI), sum(size[c(5,6),]$GNI)) palettes <- c("Greens", "Blues", "Reds", "Oranges", "Purples", "Greys") i <- 1 # This is to be replaced by for loop x <- subset(GNI2010, continent == cont[i], cex = 5) # create treemap layout(matrix(1:6, 3, byrow = TRUE), widths = widths, heights = heights) x1 <- tmPlot(x, index=c("iso3"), vSize="population", vColor="GNI", type="value", title = "", position.legend = "none", palette = palettes[i]) grid.text(cont[i], 0.5, 0.5, gp=gpar(fontsize=20, font = 2, col = "white")) ## x1 is does not make a plot as such and tmPlot overwrites layout
I understand that my decision to scale graphs based on the GNI amount is incorrect. I can ask another question about this later, as soon as I figure out how to build these treemaps in one window.
EDIT: I think the answer to this is no . Currently, you cannot save grid.newpage objects by name, and you cannot save some of them on the page because the function โerases the current device or goes to a new pageโ, as the description says. However, one can find work around. tmPlot package currently (as of March 23, 2013) does not support viewport s, but a development version.