Binary files /tmp/1jbxTTfuEq/r-cran-gridextra-0.9-1/build/vignette.rds and /tmp/2Bg1MRyc4f/r-cran-gridextra-2.0.0/build/vignette.rds differ diff -Nru r-cran-gridextra-0.9-1/debian/changelog r-cran-gridextra-2.0.0/debian/changelog --- r-cran-gridextra-0.9-1/debian/changelog 2015-07-30 07:41:44.000000000 +0000 +++ r-cran-gridextra-2.0.0/debian/changelog 2015-07-30 07:41:44.000000000 +0000 @@ -1,3 +1,11 @@ +r-cran-gridextra (2.0.0-1) unstable; urgency=low + + * New upstream release + + * debian/control: Added new (Build-)Depends: r-cran-gtable + + -- Dirk Eddelbuettel Tue, 14 Jul 2015 17:53:40 -0500 + r-cran-gridextra (0.9-1-1) unstable; urgency=low * Initial Debian release (Closes: #778660) diff -Nru r-cran-gridextra-0.9-1/debian/control r-cran-gridextra-2.0.0/debian/control --- r-cran-gridextra-0.9-1/debian/control 2015-07-30 07:41:44.000000000 +0000 +++ r-cran-gridextra-2.0.0/debian/control 2015-07-30 07:41:44.000000000 +0000 @@ -2,12 +2,12 @@ Section: gnu-r Priority: optional Maintainer: Dirk Eddelbuettel -Build-Depends: debhelper (>= 7.0.0), r-base-dev (>= 3.1.2), cdbs +Build-Depends: debhelper (>= 7.0.0), r-base-dev (>= 3.2.1), cdbs, r-cran-gtable Standards-Version: 3.9.6 Package: r-cran-gridextra Architecture: all -Depends: ${misc:Depends}, ${R:Depends} +Depends: ${misc:Depends}, ${R:Depends}, r-cran-gtable Description: GNU R package with extensions for the grid package The gridextra package provides several high-level functions to extend the grid package which provides a low-level graphics infrastructure diff -Nru r-cran-gridextra-0.9-1/DESCRIPTION r-cran-gridextra-2.0.0/DESCRIPTION --- r-cran-gridextra-0.9-1/DESCRIPTION 2012-08-09 05:38:06.000000000 +0000 +++ r-cran-gridextra-2.0.0/DESCRIPTION 2015-07-14 18:40:38.000000000 +0000 @@ -1,20 +1,24 @@ Package: gridExtra -Maintainer: baptiste +Authors@R: c(person("Baptiste", "Auguie", + email = "baptiste.auguie@gmail.com", + role = c("aut", "cre")), person("Anton", "Antonov", + email = "tonytonov@gmail.com", + role = c("ctb"))) License: GPL (>= 2) -Title: functions in Grid graphics +Title: Miscellaneous Functions for "Grid" Graphics Type: Package -Author: Baptiste Auguie -Description: misc. high-level Grid functions -Version: 0.9.1 -URL: http://code.google.com/p/gridextra/ -Date: 2012-09-08 -Depends: R(>= 2.5.0), grid -Suggests: RGraphics, pixmap, EBImage, ggplot2, lattice -Collate: 'arcText.r' 'arrange.r' 'barbedGrob.r' 'borderGrob.r' - 'colorstripGrob.r' 'ebimage.r' 'ellipseGrob.r' - 'gridExtra-package.r' 'grob-utils.r' 'polygon.regular.r' - 'ngonGrob.r' 'patternGrob.r' 'pixmap.r' 'rpattern.r' - 'stextGrob.r' 'tableGrob.r' -Packaged: 2012-08-09 00:55:23 UTC; auguieba +Description: Provides a number of user-level functions to work with "grid" graphics, notably to arrange multiple grid-based plots on a page, and draw tables. +Version: 2.0.0 +URL: https://github.com/baptiste/gridextra +VignetteBuilder: knitr +Imports: gtable, grid, grDevices, graphics, utils +Suggests: ggplot2, lattice, knitr, testthat +Collate: grob-utils.r arrangeGrob.r gridExtra-package.r tableGrob.r + ngonGrob.r +NeedsCompilation: no +Packaged: 2015-07-14 09:46:27 UTC; baptiste +Author: Baptiste Auguie [aut, cre], + Anton Antonov [ctb] +Maintainer: Baptiste Auguie Repository: CRAN -Date/Publication: 2012-08-09 05:38:06 +Date/Publication: 2015-07-14 20:40:38 diff -Nru r-cran-gridextra-0.9-1/inst/doc/arrangeGrob.html r-cran-gridextra-2.0.0/inst/doc/arrangeGrob.html --- r-cran-gridextra-0.9-1/inst/doc/arrangeGrob.html 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/doc/arrangeGrob.html 2015-07-14 09:46:27.000000000 +0000 @@ -0,0 +1,284 @@ + + + + + +Basic usage + + + + + + + + + + + + + + + + + + +

The grid package provides low-level functions to create graphical objects (grobs), and position them on a page in specific viewports. The gtable package introduced a higher-level layout scheme, arguably more amenable to user-level interaction. With the arrangeGrob/grid.arrange() pair of functions, gridExtra builds upon gtable to arrange multiple grobs on a page.

+ +

Basic usage

+ +

In this example we mix a few grobs and plots,

+ +
library(gridExtra)
+library(grid)
+library(ggplot2)
+library(lattice)
+p <- qplot(1,1)
+p2 <- xyplot(1~1)
+r <- rectGrob(gp=gpar(fill="grey90"))
+t <- textGrob("text")
+grid.arrange(t, p, p2, r, ncol=2)
+
+ +

plot of chunk basic

+ +

Title and/or annotations

+ +
gs <- lapply(1:9, function(ii) 
+  grobTree(rectGrob(gp=gpar(fill=ii, alpha=0.5)), textGrob(ii)))
+grid.arrange(grobs=gs, ncol=4, 
+               top="top label", bottom="bottom\nlabel", 
+               left="left label", right="right label")
+grid.rect(gp=gpar(fill=NA))
+
+ +

plot of chunk annotations

+ +

Complex layouts

+ +

We can provide a matrix defining the layout,

+ +
lay <- rbind(c(1,1,1,2,3),
+             c(1,1,1,4,5),
+             c(6,7,8,9,9))
+grid.arrange(grobs = gs, layout_matrix = lay)
+
+ +

plot of chunk layout

+ +

All cells are of equal size by default, but users may pass explicity widths and/or heights in any valid grid units, or as relative numbers (interpreted as null),

+ +
grid.arrange(grobs=gs[1:3], ncol=2, widths = 1:2, 
+             heights=unit(c(1,10), c("in", "mm")))
+
+ +

plot of chunk sizes

+ +

Nested layouts with arrangeGrob

+ +

The grid.arrange() function draws on the device; for more complex layouts, we may want to store the gtable and combine it with other objects, e.g. forming nested layouts. To this end, use arrangeGrob(),

+ +
g1 <- arrangeGrob(grobs = gs, layout_matrix = t(lay))
+g2 <- arrangeGrob(grobs = gs, layout_matrix = lay)
+grid.arrange(g1, g2, ncol=2)
+
+ +

plot of chunk grob

+ +

Multiple pages output

+ +

Finally, we may want to place grobs on multiple pages; the marrangeGrob() function provides a convenient interface for this, also compatible with ggsave().

+ +
set.seed(123)
+pl <- lapply(1:11, function(.x) 
+             qplot(1:10, rnorm(10), main=paste("plot", .x)))
+ml <- marrangeGrob(pl, nrow=2, ncol=2)
+## non-interactive use, multipage pdf
+## ggsave("multipage.pdf", ml)
+## interactive use; calling `dev.new` multiple times
+ml
+
+ +

plot of chunk marrange plot of chunk marrange plot of chunk marrange

+ + + + diff -Nru r-cran-gridextra-0.9-1/inst/doc/arrangeGrob.R r-cran-gridextra-2.0.0/inst/doc/arrangeGrob.R --- r-cran-gridextra-0.9-1/inst/doc/arrangeGrob.R 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/doc/arrangeGrob.R 2015-07-14 09:46:27.000000000 +0000 @@ -0,0 +1,48 @@ +## ----setup, echo=FALSE, results='hide'----------------------------------- +library(knitr) +opts_chunk$set(message=FALSE, fig.width=4, fig.height=3) + +## ----basic--------------------------------------------------------------- +library(gridExtra) +library(grid) +library(ggplot2) +library(lattice) +p <- qplot(1,1) +p2 <- xyplot(1~1) +r <- rectGrob(gp=gpar(fill="grey90")) +t <- textGrob("text") +grid.arrange(t, p, p2, r, ncol=2) + +## ----annotations--------------------------------------------------------- +gs <- lapply(1:9, function(ii) + grobTree(rectGrob(gp=gpar(fill=ii, alpha=0.5)), textGrob(ii))) +grid.arrange(grobs=gs, ncol=4, + top="top label", bottom="bottom\nlabel", + left="left label", right="right label") +grid.rect(gp=gpar(fill=NA)) + +## ----layout-------------------------------------------------------------- +lay <- rbind(c(1,1,1,2,3), + c(1,1,1,4,5), + c(6,7,8,9,9)) +grid.arrange(grobs = gs, layout_matrix = lay) + +## ----sizes, fig.height=2------------------------------------------------- +grid.arrange(grobs=gs[1:3], ncol=2, widths = 1:2, + heights=unit(c(1,10), c("in", "mm"))) + +## ----grob---------------------------------------------------------------- +g1 <- arrangeGrob(grobs = gs, layout_matrix = t(lay)) +g2 <- arrangeGrob(grobs = gs, layout_matrix = lay) +grid.arrange(g1, g2, ncol=2) + +## ----marrange------------------------------------------------------------ +set.seed(123) +pl <- lapply(1:11, function(.x) + qplot(1:10, rnorm(10), main=paste("plot", .x))) +ml <- marrangeGrob(pl, nrow=2, ncol=2) +## non-interactive use, multipage pdf +## ggsave("multipage.pdf", ml) +## interactive use; calling `dev.new` multiple times +ml + diff -Nru r-cran-gridextra-0.9-1/inst/doc/arrangeGrob.rmd r-cran-gridextra-2.0.0/inst/doc/arrangeGrob.rmd --- r-cran-gridextra-0.9-1/inst/doc/arrangeGrob.rmd 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/doc/arrangeGrob.rmd 2015-07-14 09:46:27.000000000 +0000 @@ -0,0 +1,91 @@ +--- +title: "Arranging multiple grobs on a page" +author: "Baptiste Auguie" +date: '`r Sys.Date()`' +vignette: > + %\VignetteEngine{knitr::rmarkdown} + %\VignetteIndexEntry{arrangeGrob: arranging multiple grobs on a page} +output: + knitr:::html_vignette: + toc: yes +--- + +```{r setup, echo=FALSE, results='hide'} +library(knitr) +opts_chunk$set(message=FALSE, fig.width=4, fig.height=3) +``` + +The `grid` package provides low-level functions to create graphical objects (`grobs`), and position them on a page in specific `viewports`. The `gtable` package introduced a higher-level layout scheme, arguably more amenable to user-level interaction. With the `arrangeGrob/grid.arrange()` pair of functions, `gridExtra` builds upon `gtable` to arrange multiple grobs on a page. + +## Basic usage + +In this example we mix a few grobs and plots, +```{r basic} +library(gridExtra) +library(grid) +library(ggplot2) +library(lattice) +p <- qplot(1,1) +p2 <- xyplot(1~1) +r <- rectGrob(gp=gpar(fill="grey90")) +t <- textGrob("text") +grid.arrange(t, p, p2, r, ncol=2) +``` + +## Title and/or annotations + +```{r annotations} +gs <- lapply(1:9, function(ii) + grobTree(rectGrob(gp=gpar(fill=ii, alpha=0.5)), textGrob(ii))) +grid.arrange(grobs=gs, ncol=4, + top="top label", bottom="bottom\nlabel", + left="left label", right="right label") +grid.rect(gp=gpar(fill=NA)) +``` + +## Complex layouts + +We can provide a matrix defining the layout, + +```{r layout} +lay <- rbind(c(1,1,1,2,3), + c(1,1,1,4,5), + c(6,7,8,9,9)) +grid.arrange(grobs = gs, layout_matrix = lay) +``` + +All cells are of equal size by default, but users may pass explicity `widths` and/or `heights` in any valid grid units, or as relative numbers (interpreted as `null`), + +```{r sizes, fig.height=2} +grid.arrange(grobs=gs[1:3], ncol=2, widths = 1:2, + heights=unit(c(1,10), c("in", "mm"))) +``` + +## Nested layouts with `arrangeGrob` + +The `grid.arrange()` function draws on the device; for more complex layouts, we may want to store the gtable and combine it with other objects, e.g. forming nested layouts. To this end, use `arrangeGrob()`, + +```{r grob} +g1 <- arrangeGrob(grobs = gs, layout_matrix = t(lay)) +g2 <- arrangeGrob(grobs = gs, layout_matrix = lay) +grid.arrange(g1, g2, ncol=2) +``` + +## Multiple pages output + +Finally, we may want to place grobs on multiple pages; the `marrangeGrob()` function provides a convenient interface for this, also compatible with `ggsave()`. + + +```{r marrange} +set.seed(123) +pl <- lapply(1:11, function(.x) + qplot(1:10, rnorm(10), main=paste("plot", .x))) +ml <- marrangeGrob(pl, nrow=2, ncol=2) +## non-interactive use, multipage pdf +## ggsave("multipage.pdf", ml) +## interactive use; calling `dev.new` multiple times +ml +``` + + + diff -Nru r-cran-gridextra-0.9-1/inst/doc/ngonGrob.html r-cran-gridextra-2.0.0/inst/doc/ngonGrob.html --- r-cran-gridextra-0.9-1/inst/doc/ngonGrob.html 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/doc/ngonGrob.html 2015-07-14 09:46:27.000000000 +0000 @@ -0,0 +1,254 @@ + + + + + +Basic usage + + + + + + + + + + + + + + + + + + +

The gridExtra package provides a basic implementation of regular polygons, ngonGrob()/grid.ngon, and a convenience function to draw ellipses, ellipseGrob()/grid.ellipse(). We illustrate below the basic usage of these vectorised functions.

+ +

Basic usage

+ +
library(gridExtra)
+library(grid)
+library(grid)
+N <- 5
+xy <- polygon_regular(N)*2
+
+# draw multiple polygons
+g <- ngonGrob(unit(xy[,1],"cm") + unit(0.5,"npc"),
+              unit(xy[,2],"cm") + unit(0.5,"npc"),
+              n=seq_len(N)+2, gp=gpar(fill=1:N))
+
+grid.newpage()
+grid.draw(g)
+
+ +

plot of chunk basic

+ +

Rotated and stretched polygons

+ +
g2 <- ngonGrob(unit(xy[,1],"cm") + unit(0.5,"npc"),
+              unit(xy[,2],"cm") + unit(0.5,"npc"),
+              n=seq_len(N)+2, rho=seq_len(N),
+              phase=0, angle=pi/(seq_len(N)+2),
+              size=1:N+5, gp=gpar(fill=1:N))
+
+grid.newpage()
+grid.draw(g2)
+
+ +

plot of chunk rotated

+ +

Ellipses

+ +
g3 <- ellipseGrob(unit(xy[,1],"cm") + unit(0.5,"npc"),
+                  unit(xy[,2],"cm") + unit(0.5,"npc"),
+                  angle=-2*seq(0,N-1)*pi/N+pi/2,
+                  size=5, rho=1/3, gp=gpar(fill=1:N))
+
+grid.newpage()
+grid.draw(g3)
+
+ +

plot of chunk ellipse

+ + + + diff -Nru r-cran-gridextra-0.9-1/inst/doc/ngonGrob.R r-cran-gridextra-2.0.0/inst/doc/ngonGrob.R --- r-cran-gridextra-0.9-1/inst/doc/ngonGrob.R 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/doc/ngonGrob.R 2015-07-14 09:46:27.000000000 +0000 @@ -0,0 +1,38 @@ +## ----setup, echo=FALSE, results='hide'----------------------------------- +library(knitr) +opts_chunk$set(message=FALSE, fig.width=4, fig.height=3) + +## ----basic--------------------------------------------------------------- +library(gridExtra) +library(grid) +library(grid) +N <- 5 +xy <- polygon_regular(N)*2 + +# draw multiple polygons +g <- ngonGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), + unit(xy[,2],"cm") + unit(0.5,"npc"), + n=seq_len(N)+2, gp=gpar(fill=1:N)) + +grid.newpage() +grid.draw(g) + +## ----rotated------------------------------------------------------------- +g2 <- ngonGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), + unit(xy[,2],"cm") + unit(0.5,"npc"), + n=seq_len(N)+2, rho=seq_len(N), + phase=0, angle=pi/(seq_len(N)+2), + size=1:N+5, gp=gpar(fill=1:N)) + +grid.newpage() +grid.draw(g2) + +## ----ellipse------------------------------------------------------------- +g3 <- ellipseGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), + unit(xy[,2],"cm") + unit(0.5,"npc"), + angle=-2*seq(0,N-1)*pi/N+pi/2, + size=5, rho=1/3, gp=gpar(fill=1:N)) + +grid.newpage() +grid.draw(g3) + diff -Nru r-cran-gridextra-0.9-1/inst/doc/ngonGrob.rmd r-cran-gridextra-2.0.0/inst/doc/ngonGrob.rmd --- r-cran-gridextra-0.9-1/inst/doc/ngonGrob.rmd 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/doc/ngonGrob.rmd 2015-07-14 09:46:27.000000000 +0000 @@ -0,0 +1,62 @@ +--- +title: "Regular polygons and ellipses in grid graphics" +author: "Baptiste Auguie" +date: '`r Sys.Date()`' +vignette: > + %\VignetteEngine{knitr::rmarkdown} + %\VignetteIndexEntry{ngonGrob: regular polygons and ellipses in grid graphics} +output: + knitr:::html_vignette: + toc: yes +--- + +```{r setup, echo=FALSE, results='hide'} +library(knitr) +opts_chunk$set(message=FALSE, fig.width=4, fig.height=3) +``` + +The `gridExtra` package provides a basic implementation of regular polygons, `ngonGrob()/grid.ngon`, and a convenience function to draw ellipses, `ellipseGrob()/grid.ellipse()`. We illustrate below the basic usage of these vectorised functions. + +## Basic usage + +```{r basic} +library(gridExtra) +library(grid) +library(grid) +N <- 5 +xy <- polygon_regular(N)*2 + +# draw multiple polygons +g <- ngonGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), + unit(xy[,2],"cm") + unit(0.5,"npc"), + n=seq_len(N)+2, gp=gpar(fill=1:N)) + +grid.newpage() +grid.draw(g) +``` + +## Rotated and stretched polygons + +```{r rotated} +g2 <- ngonGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), + unit(xy[,2],"cm") + unit(0.5,"npc"), + n=seq_len(N)+2, rho=seq_len(N), + phase=0, angle=pi/(seq_len(N)+2), + size=1:N+5, gp=gpar(fill=1:N)) + +grid.newpage() +grid.draw(g2) +``` + +## Ellipses + +```{r ellipse} +g3 <- ellipseGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), + unit(xy[,2],"cm") + unit(0.5,"npc"), + angle=-2*seq(0,N-1)*pi/N+pi/2, + size=5, rho=1/3, gp=gpar(fill=1:N)) + +grid.newpage() +grid.draw(g3) +``` + diff -Nru r-cran-gridextra-0.9-1/inst/doc/tableGrob.html r-cran-gridextra-2.0.0/inst/doc/tableGrob.html --- r-cran-gridextra-0.9-1/inst/doc/tableGrob.html 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/doc/tableGrob.html 2015-07-14 09:46:27.000000000 +0000 @@ -0,0 +1,362 @@ + + + + + +Basic usage + + + + + + + + + + + + + + + + + + +

Tabular data is usually formatted outside the graphics device, e.g via LaTeX, or html tables. However, in some cases it may be convenient to display small tables alongside graphics. A couple of packages offer this possibility with base graphics (plotrix for instance); the gridExtra provides the pair of tableGrob/grid.table functions for this purpose.

+ +

Basic usage

+ +
library(gridExtra)
+library(grid)
+d <- head(iris[,1:3])
+grid.table(d)
+
+ +

plot of chunk basic

+ +

Spacing

+ +

The spacing of each row/column is automatic, and will adjust to bigger cell contents. Plotmath notation may be used, with the parse=TRUE argument. Note that this is applied to individual strings of text, and reverts to standard text if parsing fails (this is useful when mixing multiline text with plotmath in different cells).

+ +
d[2,3] <- "this is very wwwwwide"
+d[1,2] <- "this\nis\ntall"
+colnames(d) <- c("alpha*integral(xdx,a,infinity)", 
+                 "this text\nis high", 'alpha/beta')
+
+tt <- ttheme_default(colhead=list(fg_params = list(parse=TRUE)))
+grid.table(d, theme=tt)
+
+ +

plot of chunk annotations

+ +

Aesthetic formatting

+ +

The formatting is controlled by themes, which are nested lists of graphical parameters. See ttheme_default and ttheme_minimal for two built-in examples. Changing a few parameters at a time amounts to modifying the list with the new values.

+ +
tt1 <- ttheme_default()
+tt2 <- ttheme_minimal()
+tt3 <- ttheme_minimal(
+  core=list(bg_params = list(fill = blues9, col=NA),
+            fg_params=list(fontface=3)), 
+  colhead=list(fg_params=list(col="navyblue")),
+  rowhead=list(fg_params=list(col="navyblue", fontface=2L)))
+
+grid.arrange(
+  tableGrob(iris[1:4, 1:2], theme=tt1),
+  tableGrob(iris[1:4, 1:2], theme=tt2),
+  tableGrob(iris[1:4, 1:2], theme=tt3),
+  nrow=1)
+
+ +

plot of chunk theme

+ +

Text justification

+ +

The text labels can be justified; the default is “centre” for the core, header, and row names. These settings can be adjusted by passing the relevant parameters of textGrob via the theme nested lists,

+ +
tt1 <- ttheme_default()
+tt2 <- ttheme_default(core=list(fg_params=list(hjust=1, x=0.9)),
+                      rowhead=list(fg_params=list(hjust=1, x=0.95)))
+tt3 <- ttheme_default(core=list(fg_params=list(hjust=0, x=0.1)),
+                      rowhead=list(fg_params=list(hjust=0, x=0)))
+grid.arrange(
+  tableGrob(mtcars[1:4, 1:2], theme=tt1),
+  tableGrob(mtcars[1:4, 1:2], theme=tt2),
+  tableGrob(mtcars[1:4, 1:2], theme=tt3),
+  nrow=1)
+
+ +

plot of chunk justify

+ +

Further gtable processing and integration

+ +

Being based on gtable, the table can be further processed. In particular, we may edit the cell sizes to align with other content on the page.

+ +
g <- g2 <- tableGrob(iris[1:4, 1:3], cols = NULL, rows=NULL)
+g2$widths <- unit(rep(1/ncol(g2), ncol(g2)), "npc")
+grid.arrange(rectGrob(), rectGrob(), nrow=1)
+grid.arrange(g, g2, nrow=1, newpage = FALSE)
+
+ +

plot of chunk sizes

+ +

Other grobs such as separating lines may be added.

+ +
g <- tableGrob(iris[1:4, 1:3], theme=ttheme_minimal())
+separators <- replicate(ncol(g) - 2, 
+                     segmentsGrob(x1 = unit(0,"npc")), 
+                     simplify=FALSE)
+g <- gtable::gtable_add_grob(g, grobs = separators, 
+                     t = 1, b = nrow(g), l = seq_len(ncol(g)-2)+2)
+grid.draw(g)
+
+ +

plot of chunk separators

+ +

We may also access and modify individual cells, e.g. to highlight a value.

+ +
g <- tableGrob(iris[1:4, 1:3])
+find_cell <- function(table, row, col, name="core-fg"){
+  l <- table$layout
+  which(l$t==row & l$l==col & l$name==name)
+}
+
+ind <- find_cell(g, 3, 2, "core-fg")
+ind2 <- find_cell(g, 2, 3, "core-bg")
+g$grobs[ind][[1]][["gp"]] <- gpar(fontsize=15, fontface="bold")
+g$grobs[ind2][[1]][["gp"]] <- gpar(fill="darkolivegreen1", col = "darkolivegreen4", lwd=5)
+grid.draw(g)
+
+ +

plot of chunk highlight

+ +

Faster tables: an alternative grid function

+ +

The tableGrob function can be very slow; unfortunately this is the price to pay for its versatility and easier implementation. We use individual textGrob and rectGrob elements for each cell, instead of relying on the vectorised implementation of these functions. The reason is practical: it is much easier to place, measure, and customise individual grobs, than modify the graphical parameters and positions of a single vectorised grob. An alternative function is presented below, using this vectorised approach, but lacking many of the customisations of tableGrob.

+ +
grid.ftable <- function(d, padding = unit(4, "mm"), ...) {
+
+  nc <- ncol(d)
+  nr <- nrow(d)
+
+  ## character table with added row and column names
+  extended_matrix <- cbind(c("", rownames(d)),   
+                           rbind(colnames(d),
+                                 as.matrix(d)))
+
+  ## string width and height
+  w <- apply(extended_matrix, 2, strwidth, "inch")
+  h <- apply(extended_matrix, 2, strheight, "inch")
+
+  widths <- apply(w, 2, max)
+  heights <- apply(h, 1, max)
+
+  padding <- convertUnit(padding, unitTo = "in", valueOnly = TRUE)
+
+  x <- cumsum(widths + padding) - 0.5 * padding
+  y <- cumsum(heights + padding) - padding
+
+  rg <- rectGrob(x = unit(x - widths/2, "in"), 
+                 y = unit(1, "npc") - unit(rep(y, each = nc + 1), "in"), 
+                 width = unit(widths + padding, "in"), 
+                 height = unit(heights + padding, "in"))
+
+  tg <- textGrob(c(t(extended_matrix)), x = unit(x - widths/2, "in"), 
+                 y = unit(1, "npc") - unit(rep(y, each = nc + 1), "in"), 
+                 just = "center")
+
+  g <- gTree(children = gList(rg, tg), ..., 
+             x = x, y = y, widths = widths, heights = heights)
+
+  grid.draw(g)
+  invisible(g)
+}
+
+grid.newpage()
+grid.ftable(head(iris, 4), gp = gpar(fill = rep(c("grey90", "grey95"), each = 6)))
+
+ +

plot of chunk ftable

+ + + + diff -Nru r-cran-gridextra-0.9-1/inst/doc/tableGrob.R r-cran-gridextra-2.0.0/inst/doc/tableGrob.R --- r-cran-gridextra-0.9-1/inst/doc/tableGrob.R 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/doc/tableGrob.R 2015-07-14 09:46:27.000000000 +0000 @@ -0,0 +1,117 @@ +## ----setup, echo=FALSE, results='hide'----------------------------------- +library(knitr) +opts_chunk$set(message=FALSE, fig.width=4, fig.height=2) + +## ----basic--------------------------------------------------------------- +library(gridExtra) +library(grid) +d <- head(iris[,1:3]) +grid.table(d) + +## ----annotations, fig.height=3------------------------------------------- +d[2,3] <- "this is very wwwwwide" +d[1,2] <- "this\nis\ntall" +colnames(d) <- c("alpha*integral(xdx,a,infinity)", + "this text\nis high", 'alpha/beta') + +tt <- ttheme_default(colhead=list(fg_params = list(parse=TRUE))) +grid.table(d, theme=tt) + + +## ----theme, fig.width=8-------------------------------------------------- +tt1 <- ttheme_default() +tt2 <- ttheme_minimal() +tt3 <- ttheme_minimal( + core=list(bg_params = list(fill = blues9, col=NA), + fg_params=list(fontface=3)), + colhead=list(fg_params=list(col="navyblue")), + rowhead=list(fg_params=list(col="navyblue", fontface=2L))) + +grid.arrange( + tableGrob(iris[1:4, 1:2], theme=tt1), + tableGrob(iris[1:4, 1:2], theme=tt2), + tableGrob(iris[1:4, 1:2], theme=tt3), + nrow=1) + +## ----justify, fig.width=8------------------------------------------------ +tt1 <- ttheme_default() +tt2 <- ttheme_default(core=list(fg_params=list(hjust=1, x=0.9)), + rowhead=list(fg_params=list(hjust=1, x=0.95))) +tt3 <- ttheme_default(core=list(fg_params=list(hjust=0, x=0.1)), + rowhead=list(fg_params=list(hjust=0, x=0))) +grid.arrange( + tableGrob(mtcars[1:4, 1:2], theme=tt1), + tableGrob(mtcars[1:4, 1:2], theme=tt2), + tableGrob(mtcars[1:4, 1:2], theme=tt3), + nrow=1) + +## ----sizes, fig.width=8-------------------------------------------------- +g <- g2 <- tableGrob(iris[1:4, 1:3], cols = NULL, rows=NULL) +g2$widths <- unit(rep(1/ncol(g2), ncol(g2)), "npc") +grid.arrange(rectGrob(), rectGrob(), nrow=1) +grid.arrange(g, g2, nrow=1, newpage = FALSE) + +## ----separators---------------------------------------------------------- +g <- tableGrob(iris[1:4, 1:3], theme=ttheme_minimal()) +separators <- replicate(ncol(g) - 2, + segmentsGrob(x1 = unit(0,"npc")), + simplify=FALSE) +g <- gtable::gtable_add_grob(g, grobs = separators, + t = 1, b = nrow(g), l = seq_len(ncol(g)-2)+2) +grid.draw(g) + +## ----highlight----------------------------------------------------------- +g <- tableGrob(iris[1:4, 1:3]) +find_cell <- function(table, row, col, name="core-fg"){ + l <- table$layout + which(l$t==row & l$l==col & l$name==name) +} + +ind <- find_cell(g, 3, 2, "core-fg") +ind2 <- find_cell(g, 2, 3, "core-bg") +g$grobs[ind][[1]][["gp"]] <- gpar(fontsize=15, fontface="bold") +g$grobs[ind2][[1]][["gp"]] <- gpar(fill="darkolivegreen1", col = "darkolivegreen4", lwd=5) +grid.draw(g) + +## ----ftable, fig.width=6------------------------------------------------- +grid.ftable <- function(d, padding = unit(4, "mm"), ...) { + + nc <- ncol(d) + nr <- nrow(d) + + ## character table with added row and column names + extended_matrix <- cbind(c("", rownames(d)), + rbind(colnames(d), + as.matrix(d))) + + ## string width and height + w <- apply(extended_matrix, 2, strwidth, "inch") + h <- apply(extended_matrix, 2, strheight, "inch") + + widths <- apply(w, 2, max) + heights <- apply(h, 1, max) + + padding <- convertUnit(padding, unitTo = "in", valueOnly = TRUE) + + x <- cumsum(widths + padding) - 0.5 * padding + y <- cumsum(heights + padding) - padding + + rg <- rectGrob(x = unit(x - widths/2, "in"), + y = unit(1, "npc") - unit(rep(y, each = nc + 1), "in"), + width = unit(widths + padding, "in"), + height = unit(heights + padding, "in")) + + tg <- textGrob(c(t(extended_matrix)), x = unit(x - widths/2, "in"), + y = unit(1, "npc") - unit(rep(y, each = nc + 1), "in"), + just = "center") + + g <- gTree(children = gList(rg, tg), ..., + x = x, y = y, widths = widths, heights = heights) + + grid.draw(g) + invisible(g) +} + +grid.newpage() +grid.ftable(head(iris, 4), gp = gpar(fill = rep(c("grey90", "grey95"), each = 6))) + diff -Nru r-cran-gridextra-0.9-1/inst/doc/tableGrob.rmd r-cran-gridextra-2.0.0/inst/doc/tableGrob.rmd --- r-cran-gridextra-0.9-1/inst/doc/tableGrob.rmd 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/doc/tableGrob.rmd 2015-07-14 09:46:27.000000000 +0000 @@ -0,0 +1,168 @@ +--- +title: "Displaying tables as grid graphics" +author: "Baptiste Auguie" +date: '`r Sys.Date()`' +vignette: > + %\VignetteEngine{knitr::rmarkdown} + %\VignetteIndexEntry{tableGrob: displaying tables as grid graphics} +output: + knitr:::html_vignette: + toc: yes +--- + +```{r setup, echo=FALSE, results='hide'} +library(knitr) +opts_chunk$set(message=FALSE, fig.width=4, fig.height=2) +``` + +Tabular data is usually formatted outside the graphics device, e.g via LaTeX, or html tables. However, in some cases it may be convenient to display *small* tables alongside graphics. A couple of packages offer this possibility with base graphics (`plotrix` for instance); the `gridExtra` provides the pair of `tableGrob/grid.table` functions for this purpose. + +## Basic usage + +```{r basic} +library(gridExtra) +library(grid) +d <- head(iris[,1:3]) +grid.table(d) +``` + +## Spacing + +The spacing of each row/column is automatic, and will adjust to bigger cell contents. Plotmath notation may be used, with the `parse=TRUE` argument. Note that this is applied to individual strings of text, and reverts to standard text if parsing fails (this is useful when mixing multiline text with plotmath in different cells). + +```{r annotations, fig.height=3} +d[2,3] <- "this is very wwwwwide" +d[1,2] <- "this\nis\ntall" +colnames(d) <- c("alpha*integral(xdx,a,infinity)", + "this text\nis high", 'alpha/beta') + +tt <- ttheme_default(colhead=list(fg_params = list(parse=TRUE))) +grid.table(d, theme=tt) + +``` + +## Aesthetic formatting + +The formatting is controlled by *themes*, which are nested lists of graphical parameters. See `ttheme_default` and `ttheme_minimal` for two built-in examples. Changing a few parameters at a time amounts to modifying the list with the new values. + +```{r theme, fig.width=8} +tt1 <- ttheme_default() +tt2 <- ttheme_minimal() +tt3 <- ttheme_minimal( + core=list(bg_params = list(fill = blues9, col=NA), + fg_params=list(fontface=3)), + colhead=list(fg_params=list(col="navyblue")), + rowhead=list(fg_params=list(col="navyblue", fontface=2L))) + +grid.arrange( + tableGrob(iris[1:4, 1:2], theme=tt1), + tableGrob(iris[1:4, 1:2], theme=tt2), + tableGrob(iris[1:4, 1:2], theme=tt3), + nrow=1) +``` + +## Text justification + +The text labels can be justified; the default is "centre" for the core, header, and row names. These settings can be adjusted by passing the relevant parameters of `textGrob` via the theme nested lists, + +```{r justify, fig.width=8} +tt1 <- ttheme_default() +tt2 <- ttheme_default(core=list(fg_params=list(hjust=1, x=0.9)), + rowhead=list(fg_params=list(hjust=1, x=0.95))) +tt3 <- ttheme_default(core=list(fg_params=list(hjust=0, x=0.1)), + rowhead=list(fg_params=list(hjust=0, x=0))) +grid.arrange( + tableGrob(mtcars[1:4, 1:2], theme=tt1), + tableGrob(mtcars[1:4, 1:2], theme=tt2), + tableGrob(mtcars[1:4, 1:2], theme=tt3), + nrow=1) +``` + +## Further gtable processing and integration + +Being based on `gtable`, the table can be further processed. In particular, we may edit the cell sizes to align with other content on the page. + +```{r sizes, fig.width=8} +g <- g2 <- tableGrob(iris[1:4, 1:3], cols = NULL, rows=NULL) +g2$widths <- unit(rep(1/ncol(g2), ncol(g2)), "npc") +grid.arrange(rectGrob(), rectGrob(), nrow=1) +grid.arrange(g, g2, nrow=1, newpage = FALSE) +``` + +Other grobs such as separating lines may be added. + +```{r separators} +g <- tableGrob(iris[1:4, 1:3], theme=ttheme_minimal()) +separators <- replicate(ncol(g) - 2, + segmentsGrob(x1 = unit(0,"npc")), + simplify=FALSE) +g <- gtable::gtable_add_grob(g, grobs = separators, + t = 1, b = nrow(g), l = seq_len(ncol(g)-2)+2) +grid.draw(g) +``` + +We may also access and modify individual cells, e.g. to highlight a value. + +```{r highlight} +g <- tableGrob(iris[1:4, 1:3]) +find_cell <- function(table, row, col, name="core-fg"){ + l <- table$layout + which(l$t==row & l$l==col & l$name==name) +} + +ind <- find_cell(g, 3, 2, "core-fg") +ind2 <- find_cell(g, 2, 3, "core-bg") +g$grobs[ind][[1]][["gp"]] <- gpar(fontsize=15, fontface="bold") +g$grobs[ind2][[1]][["gp"]] <- gpar(fill="darkolivegreen1", col = "darkolivegreen4", lwd=5) +grid.draw(g) +``` + +## Faster tables: an alternative grid function + +The `tableGrob` function can be very slow; unfortunately this is the price to pay for its versatility and easier implementation. We use individual `textGrob` and `rectGrob` elements for each cell, instead of relying on the vectorised implementation of these functions. The reason is practical: it is much easier to place, measure, and customise individual grobs, than modify the graphical parameters and positions of a single vectorised grob. An alternative function is presented below, using this vectorised approach, but lacking many of the customisations of `tableGrob`. + + +```{r ftable, fig.width=6} +grid.ftable <- function(d, padding = unit(4, "mm"), ...) { + + nc <- ncol(d) + nr <- nrow(d) + + ## character table with added row and column names + extended_matrix <- cbind(c("", rownames(d)), + rbind(colnames(d), + as.matrix(d))) + + ## string width and height + w <- apply(extended_matrix, 2, strwidth, "inch") + h <- apply(extended_matrix, 2, strheight, "inch") + + widths <- apply(w, 2, max) + heights <- apply(h, 1, max) + + padding <- convertUnit(padding, unitTo = "in", valueOnly = TRUE) + + x <- cumsum(widths + padding) - 0.5 * padding + y <- cumsum(heights + padding) - padding + + rg <- rectGrob(x = unit(x - widths/2, "in"), + y = unit(1, "npc") - unit(rep(y, each = nc + 1), "in"), + width = unit(widths + padding, "in"), + height = unit(heights + padding, "in")) + + tg <- textGrob(c(t(extended_matrix)), x = unit(x - widths/2, "in"), + y = unit(1, "npc") - unit(rep(y, each = nc + 1), "in"), + just = "center") + + g <- gTree(children = gList(rg, tg), ..., + x = x, y = y, widths = widths, heights = heights) + + grid.draw(g) + invisible(g) +} + +grid.newpage() +grid.ftable(head(iris, 4), gp = gpar(fill = rep(c("grey90", "grey95"), each = 6))) +``` + + diff -Nru r-cran-gridextra-0.9-1/inst/NEWS.md r-cran-gridextra-2.0.0/inst/NEWS.md --- r-cran-gridextra-0.9-1/inst/NEWS.md 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/NEWS.md 2015-07-11 00:27:27.000000000 +0000 @@ -0,0 +1,40 @@ +# gridExtra 2.0.0 (2015-07-11) + +* removed experimental grobs and functions not widely used (they can be found at https://github.com/baptiste/gridextra if needed) + +* arrangeGrob/grid.arrange is now based on gtable + +* tableGrob/grid.table is now based on gtable + +# gridExtra 1.0.0 (2014-10-05) + +## CLEANUP + +* several buggy functions removed + +# gridExtra 0.9.1 (2012-08-09) + +## FIX + +* small compatibility issue of arrangeGrob with new class of ggplot2 + +# gridExtra 0.9 (2012-01-06) + +## FIX + +* dependencies in examples, imports and exports + +## NEW + +* multipage output and ggsave support for grid.arrange + + +# gridExtra 0.8.5 (2011-10-26) + +## FIX + +* removed LazyLoad, deprecated in R>=2.14 + +## NEW + +* stextGrob text with a background \ No newline at end of file diff -Nru r-cran-gridextra-0.9-1/inst/test/expressions.r r-cran-gridextra-2.0.0/inst/test/expressions.r --- r-cran-gridextra-0.9-1/inst/test/expressions.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/test/expressions.r 1970-01-01 00:00:00.000000000 +0000 @@ -1,91 +0,0 @@ -library(grid) - -rowMax.units <- function(u, nrow){ # rowMax with a fake matrix of units - matrix.indices <- matrix(seq_along(u), nrow=nrow) - do.call(unit.c, lapply(seq(1, nrow), function(ii) { - max(u[matrix.indices[ii, ]]) - })) -} - -colMax.units <- function(u, ncol){ # colMax with a fake matrix of units - matrix.indices <- matrix(seq_along(u), ncol=ncol) - do.call(unit.c, lapply(seq(1, ncol), function(ii) { - max(u[matrix.indices[, ii]]) - })) -} - - -makeTableGrobs <- function(e, ncol, nrow, equal.width = F, equal.height=F, - just = c("center", "center"), - padding.h = unit(4, "mm"), padding.v=unit(4, "mm"), - gpar.text = gpar(col="black", cex=1), - gpar.fill = gpar(fill = "grey95", col="white")) { - - n <- length(e) # number of labels - - if(missing(ncol) & missing(nrow)){ - nm <- n2mfrow(n) # pretty default layout - ncol = nm[1] - nrow = nm[2] -} - -makeOneLabel <- function(label.ind){ -textGrob(label=e[label.ind], gp=gpar.text, name=paste("cells-label-",label.ind, sep="")) -} - -makeOneCell <- function(label.ind){ -rectGrob(gp=gpar.fill, name=paste("cells-fill-",label.ind, sep="")) -} - - - lg <- lapply(seq_along(e), makeOneLabel) # list of text grobs - lf <- lapply(seq_along(e), makeOneCell) # list of rect grobs - - wg <- lapply(lg, grobWidth) # list of grob widths - hg <- lapply(lg, grobHeight) # list of grob heights - - widths.all <- do.call(unit.c, wg) # all grob widths - heights.all <- do.call(unit.c, hg) #all grob heights - - widths <- colMax.units(widths.all, ncol) + padding.h # all column widths - heights <- rowMax.units(heights.all, nrow) + padding.v # all row heights - - if(equal.width) - widths <- rep(max(widths), length(widths)) - if(equal.height) - heights <- rep(max(heights), length(heights)) - - gcells = frameGrob(name="table.cells", vp = "cells", - layout = grid.layout(nrow, ncol, width=widths, height=heights, just=just) ) - - label.ind <- 1 # index running accross labels - - for (ii in seq(1, ncol, 1)) { - for (jj in seq(1, nrow, 1)) { - - gcells = placeGrob(gcells, lf[[label.ind]], row=jj, col=ii) - gcells = placeGrob(gcells, lg[[label.ind]], row=jj, col=ii) - - label.ind <- label.ind + 1 - } - } - - gl = gList( gcells) - - gl -} - -exprGrob <- function(e, ncol=n2mfrow(length(e))[2], nrow=n2mfrow(length(e))[1], ...) { - gTree(e=e, ncol=ncol, nrow=nrow, cl="expr", ...) -} - -drawDetails.expr <- function(x, recording=TRUE){ -grid.draw(gTree(children=makeTableGrobs(x$e, x$ncol, x$nrow), - childrenvp=viewport(name="cells"))) - -} - -grid.expr <- function(...){ - grid.draw(exprGrob(...)) - -} diff -Nru r-cran-gridextra-0.9-1/inst/test/tableGrob2.r r-cran-gridextra-2.0.0/inst/test/tableGrob2.r --- r-cran-gridextra-0.9-1/inst/test/tableGrob2.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/test/tableGrob2.r 1970-01-01 00:00:00.000000000 +0000 @@ -1,239 +0,0 @@ -#' display a data.frame -#' -#' uses Grid graphics to display a data.frame on a graphics page -#' @aliases tableGrob2 grid.table2 -#' @title tableGrob2 -#' @param d data.frame -#' @param name -#' @param gp -#' @param show.rownames logical -#' @param show.colnames logical -#' @param equal.width logical -#' @param core.vsep logical -#' @param core.hsep logical -#' @param head.vsep logical -#' @param head.hsep logical -#' @param core.fill colour -#' @param head.fill colour -#' @param core.border colour -#' @param head.border colour -#' @param core.text colour -#' @param head.text colour -#' @return a grob -#' @seealso \code{grid.segments}, \code{grid.points} -#' @examples -#' tc = textConnection(" -#' carat VeryLongWordIndeed color clarity depth -#' 14513 1.35 Ideal J VS2 61.4 -#' 28685 0.30 Good G VVS1 64.0 -#' 50368 0.75 Ideal F SI2 59.2") -#' d = read.table(tc,head=T) -#' close(tc) -#' grid.newpage() -#' g = grid.table2(d) -#' grid.ls(g) -#' grid.edit("top-head-fill-5", gp=gpar(fill="red")) -#' grid.edit("cells-label-33", label=expression(alpha),gp=gpar(col="orange")) -#' grid.newpage() -#' grid.table2(d, core.fill ="red", head.text = "green", -#' core.text = "blue", head.fill ="cyan",head.border="black",core.border="magenta") -#' grid.newpage() -#' grid.table2(d,equal=T) -#' grid.newpage() -#' grid.table2(d,show.rownames=F) -#' grid.newpage() -#' grid.table2(d,show.colnames=F) - - -makeTableGrobs2 <- function(d, widths, left.width, content.width, top.height, content.height, - just = c("left", "top"), - show.rownames=T,show.colnames=T, - core.vsep=T, core.hsep=T, - head.vsep=T, head.hsep=T, - core.fill = "grey95", - head.fill = "grey90", - core.border = "white", - head.border = "white", - core.text = "black", - head.text = "black") { - - ncol = ncol(d) - nrow = nrow(d) - -# inner cells - gcells = frameGrob(name="table.cells", vp = "cells", - layout = grid.layout(nrow, ncol, just=just, - widths = widths, - heights = unit(rep(1, nrow), "lines") )) - - for (ii in seq(1, ncol, 1)) { - for (jj in seq(1, nrow, 1)) { - gcells = placeGrob(gcells, rectGrob(gp=gpar(fill = core.fill, col=NA), name=paste("cells-fill-",ii,jj,sep="")), row=jj, col=ii) - if (core.hsep ) - gcells = placeGrob(gcells, segmentsGrob(0,0,0,1, gp=gpar(col = core.border)), - row=jj, col=ii) - if (core.vsep) - gcells = placeGrob(gcells, segmentsGrob(0,0,1,0, gp=gpar(col = core.border)), - row=jj, col=ii) - gcells = placeGrob(gcells, textGrob(label=d[jj,ii], gp=gpar(col=core.text), name=paste("cells-label-",ii,jj,sep="")), - row=jj, col=ii) - } - } - -if (show.colnames) -{ -# top header - gtop = frameGrob(name="table.header.top", vp = "header.top", - layout = grid.layout(1, ncol, just=just, - widths = widths, - heights = unit(1, "lines") )) - - for (ii in seq(1, ncol, 1)) { - gtop = placeGrob(gtop, rectGrob(gp=gpar(fill = head.fill,col=NA), name=paste("top-head-fill-",ii,sep="")), row=1, col=ii) - if (head.hsep) - gtop = placeGrob(gtop, segmentsGrob(0,0,0,1,gp=gpar(col = head.border)), row=1, col=ii) - if (head.vsep) - gtop = placeGrob(gtop, segmentsGrob(0,0,1,0,gp=gpar(col = head.border)), row=1, col=ii) - gtop = placeGrob(gtop, - textGrob(label=colnames(d)[ii], gp=gpar(col=head.text,fontface="bold"), name=paste("top-head-label-", ii,sep="")), row=1, col=ii) - } -} - - -if (show.rownames) -{ -# left header - gleft = frameGrob(name="table.header.left", vp="header.left", - layout = grid.layout(nrow, 1, just=just, - widths = left.width, - heights = unit(1, "lines") )) - - for (jj in seq(1, nrow, 1)) { - gleft = placeGrob(gleft, rectGrob(gp=gpar(fill = head.fill,col=NA), name=paste("left-head-fill-", jj,sep="")), row=jj, col=1) - if (head.hsep) - gleft = placeGrob(gleft, segmentsGrob(1,0,1,1, gp=gpar(col = head.border)), row=jj, col=1) - if (head.vsep) - gleft = placeGrob(gleft, segmentsGrob(0,1,1,1, gp=gpar(col = head.border)), row=jj, col=1) - gleft = placeGrob(gleft, - textGrob(label=rownames(d)[jj],gp=gpar(col=head.text,fontface="bold"), name=paste("left-head-label-", jj,sep="")), row=jj, col=1) - } -} - -if (show.rownames & show.colnames) -gl = gList( gcells, gleft, gtop) - -if (!show.rownames & !show.colnames) -gl = gList( gcells) - -if (show.rownames & !show.colnames) -gl = gList( gcells, gleft) - -if (!show.rownames & show.colnames) -gl = gList( gcells, gtop) - -gl -} - - - - -makeTableVps2 <- function(show.rownames=T,show.colnames=T) { - -if (show.rownames & show.colnames) -vl = vpList(viewport(name="cells", layout.pos.row = 2, layout.pos.col = 2), - viewport(name="header.top", layout.pos.row = 1, layout.pos.col = 2), - viewport(name="header.left", layout.pos.row = 2, layout.pos.col = 1) -) - -if (!show.rownames & !show.colnames) -vl = vpList(viewport(name="cells", layout.pos.row = 1, layout.pos.col = 1) -) - -if (show.rownames & !show.colnames) -vl = vpList(viewport(name="cells", layout.pos.row = 1, layout.pos.col = 2), - viewport(name="header.left", layout.pos.row = 1, layout.pos.col = 1) -) - -if (!show.rownames & show.colnames) -vl = vpList(viewport(name="cells", layout.pos.row = 2, layout.pos.col = 1), - viewport(name="header.top", layout.pos.row = 1, layout.pos.col = 1) -) - -vl -} - - -tableGrob2 <- function(d, - name=NULL, gp=NULL, show.rownames=T, show.colnames=T, equal.width=F, - just = c("left", "top"), - core.vsep=T, core.hsep=T, - head.vsep=T, head.hsep=T, - core.fill = "grey95", - head.fill = "grey90", - core.border = "white", - head.border = "white", - core.text = "black", - head.text = "black") { - - ncol = ncol(d) - nrow = nrow(d) - - dm = as.matrix(d) - dm = cbind(rownames(d), dm) - dm = rbind(colnames(dm), dm) - - left.width = convertUnit(max(stringWidth(rownames(dm))), "mm") + rep(unit(4,"mm"), ncol ) - top.height = unit(1,"line") - content.height = unit(nrow,"line") - - if(equal.width){ - widths = rep(convertUnit(max(stringWidth(dm)), "mm") + unit(4,"mm"), ncol ) - left.width = widths[1] - } - - if(!equal.width) - widths <- unit(4,"mm") + - do.call(unit.c, lapply(seq(2, ncol(dm), 1), - function(.col) convertUnit(max(stringWidth(dm[seq(1+!show.colnames, nrow(dm), 1),.col])), "mm"))) - - content.width = sum(convertUnit(widths, "mm")) - - heights = rep( unit(1,"line"), nrow + show.colnames) - - ws = if(show.rownames) unit.c(left.width,content.width) else content.width - hs = if(show.colnames) unit.c(top.height, content.height) else content.height - vp.table = viewport(name="table", layout= - grid.layout(1+show.colnames,1+show.rownames, width = ws, - height = hs, just=c("left", "top") - ) - ) - - - g <- gTree(nrow=nrow, ncol=ncol, just = just, show.rownames=show.rownames, show.colnames=show.colnames, - children = makeTableGrobs2(d, widths, left.width, content.width, top.height, content.height, - just = just, - show.rownames=show.rownames, show.colnames=show.colnames, - core.vsep=core.vsep, core.hsep=core.hsep, - head.vsep=head.vsep, head.hsep=head.hsep, - core.fill = core.fill, - head.fill = head.fill, - core.border = core.border, - head.border = head.border, - core.text = core.text, - head.text = head.text), - gp=gp, name=name, vp = vp.table, - childrenvp = makeTableVps2(show.rownames=show.rownames,show.colnames=show.colnames), - cl = "tableGrob") - g -} - -grid.table2 <- function(...) { - g <- tableGrob2(...) - grid.draw(g) -invisible(g) -} - - - - - diff -Nru r-cran-gridextra-0.9-1/inst/test/tableGrob-grobnames.r r-cran-gridextra-2.0.0/inst/test/tableGrob-grobnames.r --- r-cran-gridextra-0.9-1/inst/test/tableGrob-grobnames.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/test/tableGrob-grobnames.r 1970-01-01 00:00:00.000000000 +0000 @@ -1,112 +0,0 @@ - - -grobii <- function(d, gp=gpar(), name="row-label-", - just="center", parse=TRUE){ - x <- switch(just, "center"=0.5, "right"=0.95, "left"=0.1) - function(ii){ - g <- d[[ii]] - gTree(x=x, children=gList(g), just=just, gp=gp, name=paste(name, ii, sep="")) - } -} - -makeTableGrobs <- function(content, rnames=NULL, cnames=NULL, - nrow, ncol, parse=TRUE, - row.just="center", col.just="center", core.just="center", - equal.width = FALSE, equal.height=FALSE, - gpar.coretext = gpar(col="black", cex=1), - gpar.coltext = gpar(col="black", cex=1, fontface="bold"), - gpar.rowtext = gpar(col="black", cex=0.8, fontface="italic"), - h.odd.alpha = 1, h.even.alpha = 1, - v.odd.alpha = 1, v.even.alpha = 1, - gpar.corefill = gpar(fill = "grey95", col="white"), - gpar.rowfill = gpar(fill = "grey90", col="white"), - gpar.colfill = gpar(fill = "grey90", col="white")) { - - ncontent <- length(content) # number of labels - nrnames <- length(rnames) # number of row labels - ncnames <- length(cnames) # number of col labels - - - ## define some functions to generate named grobs - makeOneRowname <- if(all(is.character(rnames))) - textii(d=rnames, gp=gpar.rowtext, name="row-label-", just=row.just, parse=parse) else - grobii(d=rnames, gp=gpar.rowtext, name="row-label-", just=row.just) - - makeOneColname <- if(all(is.character(cnames))) - textii(d=cnames, gp=gpar.coltext, name="col-label-", just=col.just, parse=parse) else - grobii(d=cnames, gp=gpar.coltext, name="col-label-", just=col.just) - - makeOneLabel <- textii(d=content, gp=gpar.coretext, name="core-label-", just=core.just, parse=parse) - - - gp.corefillee <- gp.corefilleo <- gp.corefilloe <- gp.corefilloo <- gpar.corefill - gp.corefillee[["alpha"]] <- h.even.alpha * v.even.alpha - gp.corefilloe[["alpha"]] <- h.odd.alpha * v.even.alpha - gp.corefilloo[["alpha"]] <- h.odd.alpha * v.odd.alpha - gp.corefilleo[["alpha"]] <- h.even.alpha * v.odd.alpha - - gpar.corefill <- rep(c(rep(c(list(gp.corefillee), list(gp.corefilloe)), length.out=nrow), - rep(c(list(gp.corefilleo), list(gp.corefilloo)), length.out=nrow)), - length.out=ncontent) - - gp.rowfille <- gp.rowfillo <- gpar.rowfill - gp.rowfille[["alpha"]] <- h.even.alpha - gp.rowfillo[["alpha"]] <- h.odd.alpha - - gpar.rowfill <- rep(c(list(gp.rowfille), list(gp.rowfillo)), nrow) - - gp.colfille <- gp.colfillo <- gpar.colfill - gp.colfille[["alpha"]] <- v.even.alpha - gp.colfillo[["alpha"]] <- v.odd.alpha - - gpar.colfill <- rep(c(list(gp.colfille), list(gp.colfillo)), ncol) - - makeOneCell <- rectii(gp=gpar.corefill, name="core-fill-") - makeOneRowfill <- rectii(gp=gpar.rowfill, name="row-fill-") - makeOneColfill <- rectii(gp=gpar.colfill, name="col-fill-") - - ## in case of missing row(col) names, make a list of virtualGrobs - ## else, a list of rectGrobs with incremental names - if(is.null(rnames)){ - lrt <- lrf <- replicate(nrow, virtualGrob, simplify=FALSE)} else { - lrt <- lapply(seq_along(rnames), makeOneRowname) # list of text grobs - lrf <- lapply(seq_along(rnames), makeOneRowfill) # list of rect grobs - } - if(is.null(cnames)){ - lct <- lcf <- replicate(ncol, virtualGrob, simplify=FALSE)} else { - lct <- lapply(seq_along(cnames), makeOneColname) # list of text grobs - lcf <- lapply(seq_along(cnames), makeOneColfill) # list of rect grobs - } - ## the content consists of textGrobs and rectGrobs - lit <- lapply(seq_along(content), makeOneLabel) # list of text grobs - lif <- lapply(seq_along(content), makeOneCell) # list of rect grobs - - ## here the grobs are arranged and permuted in a list to fill a matrix column by column - lgt <- c(list(virtualGrob), lrt, interleaven(lct, lit, nrow)) # all labels in order - lgf <- c(list(virtualGrob), lrf, interleaven(lcf, lif, nrow)) # all labels in order - - ## retrieve the widths and heights of all textGrobs (including some virtualGrobs) - wg <- lapply(lgt, grobWidth) # list of grob widths - hg <- lapply(lgt, grobHeight) # list of grob heights - - ## concatenate this units - widths.all <- do.call(unit.c, wg) # all grob widths - heights.all <- do.call(unit.c, hg) #all grob heights - - ## matrix-like operations on units to define the table layout - widths <- colMax.units(widths.all, ncol+1) # all column widths - heights <- rowMax.units(heights.all, nrow+1) # all row heights - - ## equal width or equal height (all except rows and cols) - nwidths <- length(widths) - nheights <- length(heights) - if(equal.width) - widths <- unit.c(widths[[1]], rep(max(widths[seq(2, nwidths)]), nwidths-1)) - if(equal.height) - heights <- unit.c(heights[[1]], rep(max(heights[seq(2, nheights)]), nheights-1)) - - ## return a list containing lists of grobs, and the dimensions for a rectangular layout - list(lgt=lgt, lgf=lgf, nrow=nrow, ncol=ncol, widths=widths, heights=heights) -} - -utils::assignInNamespace("makeTableGrobs", makeTableGrobs, "gridExtra") diff -Nru r-cran-gridextra-0.9-1/inst/tests/testthat/test-arrangeGrob.R r-cran-gridextra-2.0.0/inst/tests/testthat/test-arrangeGrob.R --- r-cran-gridextra-0.9-1/inst/tests/testthat/test-arrangeGrob.R 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/tests/testthat/test-arrangeGrob.R 2015-07-11 00:20:03.000000000 +0000 @@ -0,0 +1,50 @@ +library(gridExtra) +library(testthat) +library(grid) +r <- rectGrob(gp=gpar(fill="grey90")) + +context("Checking layout") + +test_that("nrow/ncol define a layout", { + expect_that(dim(arrangeGrob(r,r,r)), equals(c(3,1))) + expect_that(dim(arrangeGrob(r,r,r, nrow=2)), equals(c(2,2))) + expect_that(dim(arrangeGrob(r,r,r, ncol=2)), equals(c(2,2))) + expect_that(dim(arrangeGrob(r,r,r, ncol=4)), equals(c(1,4))) + expect_that(dim(arrangeGrob(r,r,r, nrow=4)), equals(c(4,1))) + expect_that(dim(arrangeGrob(r,r,r, nrow=1)), equals(c(1,3))) + expect_that(dim(arrangeGrob(r,r,r, ncol=1)), equals(c(3,1))) + expect_that(dim(arrangeGrob(r,r,r, ncol=2,nrow=2)), equals(c(2,2))) + expect_that(dim(arrangeGrob(r,r,r, ncol=3,nrow=4)), equals(c(4,3))) + expect_error(arrangeGrob(r,r,r, ncol=1,nrow=1)) +}) + +test_that("widths/heights define a layout", { + expect_that(dim(arrangeGrob(r,r,r, widths=1)), equals(c(3,1))) + expect_that(dim(arrangeGrob(r,r,r, heights=1)), equals(c(1,3))) + expect_that(dim(arrangeGrob(r,r,r, widths=1:3)), equals(c(1,3))) + expect_that(dim(arrangeGrob(r,r,r, widths=1:5)), equals(c(1,5))) + expect_that(dim(arrangeGrob(r,r,r, heights=1:3)), equals(c(3,1))) + expect_that(dim(arrangeGrob(r,r,r, heights=1:5)), equals(c(5,1))) + expect_that(dim(arrangeGrob(r,r,r, widths=1:5)), equals(c(1,5))) + expect_that(dim(arrangeGrob(r,r,r, widths=1:5, heights=1:5)), + equals(c(5,5))) + expect_error(arrangeGrob(r,r,r, widths=1, heights=1)) +}) + +test_that("combinations of nrow/ncol and widths/heights define a layout", { + + expect_that(dim(arrangeGrob(r,r,r, nrow=2, widths=1:3)), + equals(c(2,3))) + expect_that(dim(arrangeGrob(r,r,r, ncol=2, heights=1:3)), + equals(c(3,2))) + expect_that(dim(arrangeGrob(r,r,r, ncol=2, widths=1:2)), + equals(c(2,2))) + expect_that(dim(arrangeGrob(r,r,r, nrow=2, heights=1:2)), + equals(c(2,2))) + + expect_error(arrangeGrob(r,r,r, ncol=2, widths=1:3)) + expect_error(arrangeGrob(r,r,r, nrow=2, heights=1:3)) + +}) + + diff -Nru r-cran-gridextra-0.9-1/inst/tests/testthat/test-tableGrob.R r-cran-gridextra-2.0.0/inst/tests/testthat/test-tableGrob.R --- r-cran-gridextra-0.9-1/inst/tests/testthat/test-tableGrob.R 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/tests/testthat/test-tableGrob.R 2015-07-11 00:10:27.000000000 +0000 @@ -0,0 +1,15 @@ +library(gridExtra) +library(testthat) +library(grid) + +m <- iris[1:4, 1:3] + +context("Checking tableGrob layout") + +test_that("tableGrob has the correct size", { + expect_that(dim(tableGrob(m)), equals(c(5,4))) + expect_that(dim(tableGrob(m, rows = NULL)), equals(c(5,3))) + expect_that(dim(tableGrob(m, cols = NULL)), equals(c(4,4))) + expect_that(dim(tableGrob(m, rows = NULL, cols = NULL)), + equals(c(4,3))) +}) diff -Nru r-cran-gridextra-0.9-1/inst/tests/testthat.r r-cran-gridextra-2.0.0/inst/tests/testthat.r --- r-cran-gridextra-0.9-1/inst/tests/testthat.r 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/inst/tests/testthat.r 2015-07-10 23:53:27.000000000 +0000 @@ -0,0 +1,4 @@ +library(gridExtra) +library(testthat) + +test_check("gridExtra") diff -Nru r-cran-gridextra-0.9-1/man/arcTextGrob.Rd r-cran-gridextra-2.0.0/man/arcTextGrob.Rd --- r-cran-gridextra-0.9-1/man/arcTextGrob.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/arcTextGrob.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,48 +0,0 @@ -\name{arcTextGrob} -\alias{arcTextGrob} -\alias{grid.arcText} -\title{place text labels on a circle and display relations with arcs} -\usage{ - arcTextGrob(x = unit(0.5, "npc"), y = unit(0.5, "npc"), - labels = LETTERS, - links = sample(seq_along(labels), 50, replace = TRUE), - default.units = "npc", gp = gpar(), ...) -} -\arguments{ - \item{x}{x unit} - - \item{y}{y unit} - - \item{labels}{text labels} - - \item{links}{integer vector} - - \item{default.units}{default units} - - \item{gp}{gpar} - - \item{...}{additional params (unused)} -} -\value{ - grob -} -\description{ - place text labels on a circle and display relations with - arcs -} -\examples{ -library(grid) -set.seed(1234) -grid.newpage() -grid.arcText() -} -\seealso{ - Other grob userlevel: \code{\link{barbedGrob}}, - \code{\link{borderGrob}}, \code{\link{colorstripGrob}}, - \code{\link{ebimageGrob}}, \code{\link{ellipseGrob}}, - \code{\link{interleaven}}, \code{\link{ngonGrob}}, - \code{\link{patternGrob}}, \code{\link{pixmapGrob}}, - \code{\link{rpatternGrob}}, \code{\link{stextGrob}}, - \code{\link{tableGrob}}, \code{\link{virtualGrob}} -} - diff -Nru r-cran-gridextra-0.9-1/man/arrangeGrob.Rd r-cran-gridextra-2.0.0/man/arrangeGrob.Rd --- r-cran-gridextra-0.9-1/man/arrangeGrob.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/arrangeGrob.Rd 2015-07-14 08:56:15.000000000 +0000 @@ -1,51 +1,88 @@ +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/arrangeGrob.r \name{arrangeGrob} \alias{arrangeGrob} -\alias{drawDetails.lattice} \alias{grid.arrange} -\alias{latticeGrob} -\alias{print.arrange} -\title{arrangeGrob} +\alias{marrangeGrob} +\title{Arrange multiple grobs on a page} \usage{ - arrangeGrob(..., as.table = FALSE, clip = TRUE, - main = NULL, sub = NULL, left = NULL, legend = NULL) +arrangeGrob(..., grobs = list(...), layout_matrix, vp = NULL, + name = "arrange", as.table = TRUE, respect = FALSE, clip = "off", + nrow = NULL, ncol = NULL, widths = NULL, heights = NULL, top = NULL, + bottom = NULL, left = NULL, right = NULL, padding = unit(0.5, "line")) + +grid.arrange(..., newpage = TRUE) + +marrangeGrob(grobs, ncol, nrow, ..., top = quote(paste("page", g, "of", + pages))) } \arguments{ - \item{...}{plots of class ggplot2, trellis, or grobs, and - valid arguments to grid.layout} +\item{...}{grobs, gtables, ggplot or trellis objects} + +\item{grobs}{list of grobs} + +\item{layout_matrix}{optional layout} + +\item{vp}{viewport} + +\item{name}{argument of gtable} + +\item{as.table}{logical: bottom-left to top-right or top-left to bottom-right} + +\item{respect}{argument of gtable} + +\item{clip}{argument of gtable} - \item{main}{string, or grob (requires a well-defined - height, see example)} +\item{nrow}{argument of gtable} - \item{sub}{string, or grob (requires a well-defined - height, see example)} +\item{ncol}{argument of gtable} - \item{legend}{string, or grob (requires a well-defined - width, see example)} +\item{widths}{argument of gtable} - \item{left}{string, or grob (requires a well-defined - width, see example)} +\item{heights}{argument of gtable} - \item{as.table}{logical: bottom-left to top-right or - top-left to bottom-right} +\item{top}{optional string, or grob} - \item{clip}{logical: clip every object to its viewport} +\item{bottom}{optional string, or grob} + +\item{left}{optional string, or grob} + +\item{right}{optional string, or grob} + +\item{padding}{unit of length one, margin around annotations} + +\item{newpage}{open a new page} } \value{ - return a frame grob; side-effect (plotting) if plot=T +arrangeGrob returns a gtable + +marrangeGrobm returns a list of class arrangelist } \description{ - arrange ggplot2, lattice, and grobs on a page +Set up a gtable layout to place multiple grobs on a page +} +\details{ +Using marrangeGrob, if the layout specifies both nrow and ncol, the list of grobs can be split into multiple pages. On interactive devices print open new windows, whilst non-interactive devices such as pdf call grid.newpage() between the drawings. } +\section{Functions}{ +\itemize{ +\item \code{arrangeGrob}: return a grob without drawing + +\item \code{grid.arrange}: draw on the current device + +\item \code{marrangeGrob}: interface to arrangeGrob that can dispatch on multiple pages +}} \examples{ +library(grid) +grid.arrange(rectGrob(), rectGrob()) \dontrun{ -require(ggplot2) -plots = lapply(1:5, function(.x) qplot(1:10,rnorm(10), main=paste("plot",.x))) -require(gridExtra) -do.call(grid.arrange, plots) -require(lattice) -grid.arrange(qplot(1:10), xyplot(1:10~1:10), -tableGrob(head(iris)), nrow=2, as.table=TRUE, main="test main", -sub=textGrob("test sub", gp=gpar(font=2))) +library(ggplot2) +pl <- lapply(1:11, function(.x) qplot(1:10,rnorm(10), main=paste("plot",.x))) +ml <- marrangeGrob(pl, nrow=2, ncol=2) +## interactive use; open new devices +ml +## non-interactive use, multipage pdf +ggsave("multipage.pdf", ml) } } diff -Nru r-cran-gridextra-0.9-1/man/barbedGrob.Rd r-cran-gridextra-2.0.0/man/barbedGrob.Rd --- r-cran-gridextra-0.9-1/man/barbedGrob.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/barbedGrob.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,78 +0,0 @@ -\name{barbedGrob} -\alias{barbedGrob} -\alias{grid.barbed} -\title{barbedGrob} -\usage{ - barbedGrob(x = stats::runif(10), y = stats::runif(10), - size = unit(sample(1:4, 10, replace = TRUE), "char"), - pch = 21, arrow = NULL, space = 1, only.lines = FALSE, - gp = gpar(), name = NULL, default.units = "npc", - vp = NULL) -} -\arguments{ - \item{x}{coordinates} - - \item{y}{coordinates} - - \item{size}{unit vector for the symbols} - - \item{pch}{vector of symbol types} - - \item{space}{numeric scaling factor for the exclusion - zone} - - \item{only.lines}{logical: should only split lines be - returned?} - - \item{arrow}{arrow passed to grid.segments} - - \item{gp}{gpar() object for the symbols} - - \item{name}{grob name} - - \item{default.units}{default units} - - \item{vp}{viewport} -} -\value{ - a grob -} -\description{ - plot lines and symbols -} -\examples{ -set.seed(1234) -grid.barbed(name="test") -grid.edit("test", gp=gpar(fill="blue", lwd=3)) -grid.edit("test::points", pch=22) -grid.newpage() -g <- -barbedGrob(size=unit(1:5, "char"), only=FALSE, - gp=gpar(col="red", lex=3, fill="blue", alpha=0.5, pch=3)) - -pushViewport(vp=viewport(width=1, height=1)) -grid.rect(gp=gpar(fill="thistle2")) -grid.grill(gp=gpar(col="lavenderblush1", lwd=3, lty=3)) -grid.draw(g) -x <- c(0.2, 0.7) -y <- x -dev.new(width=3, height=7) -grid.newpage() -g <- -barbedGrob(x, y, size=unit(c(2, 10), "mm")) -pushViewport(vp=viewport(width=1, height=1)) -grid.draw(g) -grid.points(x, y, pch=3) -} -\seealso{ - \code{grid.segments}, \code{grid.points} - - Other grob userlevel: \code{\link{arcTextGrob}}, - \code{\link{borderGrob}}, \code{\link{colorstripGrob}}, - \code{\link{ebimageGrob}}, \code{\link{ellipseGrob}}, - \code{\link{interleaven}}, \code{\link{ngonGrob}}, - \code{\link{patternGrob}}, \code{\link{pixmapGrob}}, - \code{\link{rpatternGrob}}, \code{\link{stextGrob}}, - \code{\link{tableGrob}}, \code{\link{virtualGrob}} -} - diff -Nru r-cran-gridextra-0.9-1/man/borderGrob.Rd r-cran-gridextra-2.0.0/man/borderGrob.Rd --- r-cran-gridextra-0.9-1/man/borderGrob.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/borderGrob.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,49 +0,0 @@ -\name{borderGrob} -\alias{borderGrob} -\alias{grid.border} -\title{borderGrob} -\usage{ - borderGrob(type = 1, colour = "white", vp = NULL, ...) -} -\arguments{ - \item{type}{which borders to draw} - - \item{colour}{colour} - - \item{...}{additional arguments passed to gpar()} - - \item{vp}{viewport} -} -\value{ - a grob -} -\description{ - an open rectangular borderdraw -} -\examples{ -pushViewport(viewport(width=0.5, height=0.5, layout=grid.layout(4, 4, w=0.9, height=0.9))) -vp = viewport(width=0.9, height=0.9) -type <- 1 -for(ii in 1:4){ - for(jj in 1:4){ - pushViewport(viewport(layout.pos.r=ii, layout.pos.c=jj)) - grid.rect(gp=gpar(col="grey",fill="black")) - grid.text(paste("t = ", type), gp=gpar(col="white")) - grid.border(type, vp=vp) - upViewport() - type <- type + 1 - } -} -} -\seealso{ - \code{grid.segments}, \code{grid.points} - - Other grob userlevel: \code{\link{arcTextGrob}}, - \code{\link{barbedGrob}}, \code{\link{colorstripGrob}}, - \code{\link{ebimageGrob}}, \code{\link{ellipseGrob}}, - \code{\link{interleaven}}, \code{\link{ngonGrob}}, - \code{\link{patternGrob}}, \code{\link{pixmapGrob}}, - \code{\link{rpatternGrob}}, \code{\link{stextGrob}}, - \code{\link{tableGrob}}, \code{\link{virtualGrob}} -} - diff -Nru r-cran-gridextra-0.9-1/man/colorstripGrob.Rd r-cran-gridextra-2.0.0/man/colorstripGrob.Rd --- r-cran-gridextra-0.9-1/man/colorstripGrob.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/colorstripGrob.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,42 +0,0 @@ -\name{colorstripGrob} -\alias{colorstripGrob} -\alias{grid.colorstrip} -\title{colorstrip} -\usage{ - colorstripGrob(fill = 1:3, colour = fill, draw = TRUE, - raster = FALSE, - direction = c("vertical", "horizontal")) -} -\arguments{ - \item{fill}{vector of colours} - - \item{colour}{vector of colours} - - \item{draw}{logical} - - \item{direction}{direction (horizontal or vertical)} - - \item{raster}{logical, use grid.raster (with - interpolation)} -} -\value{ - a grob -} -\description{ - strip of colors -} -\examples{ -colorstripGrob(c("#E41A1C", "#377EB8", "#4DAF4A")) -} -\seealso{ - \code{grid.rect} - - Other grob userlevel: \code{\link{arcTextGrob}}, - \code{\link{barbedGrob}}, \code{\link{borderGrob}}, - \code{\link{ebimageGrob}}, \code{\link{ellipseGrob}}, - \code{\link{interleaven}}, \code{\link{ngonGrob}}, - \code{\link{patternGrob}}, \code{\link{pixmapGrob}}, - \code{\link{rpatternGrob}}, \code{\link{stextGrob}}, - \code{\link{tableGrob}}, \code{\link{virtualGrob}} -} - diff -Nru r-cran-gridextra-0.9-1/man/ebimageGrob.Rd r-cran-gridextra-2.0.0/man/ebimageGrob.Rd --- r-cran-gridextra-0.9-1/man/ebimageGrob.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/ebimageGrob.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,55 +0,0 @@ -\name{ebimageGrob} -\alias{ebimageGrob} -\title{create a grob from EBImage object} -\usage{ - ebimageGrob(pic, x = 0.5, y = 0.5, scale = 1, - raster = FALSE, angle = NULL, ...) -} -\arguments{ - \item{pic}{object of class Image} - - \item{x}{x unit} - - \item{y}{y unit} - - \item{scale}{numeric scale factor} - - \item{raster}{logical: use rasterGrob(R>=2.11) or - imageGrob(RGraphics)} - - \item{angle}{numeric: angle in degrees} - - \item{...}{optional grob parameters, passed to imageGrob - or rasterGrob} -} -\value{ - a gTree of class 'ebimage', with natural width and height - in points -} -\description{ - create a grob from EBImage object -} -\details{ - Very primitive function, using RGraphics' imageGrob or - rasterGrob (R>2.11) -} -\examples{ -\dontrun{ -library(EBImage) -library(RGraphics) - x <- readImage("http://www.google.com/logos/teachersday09.gif") -g1 <- ebimageGrob(x) -dev.new(width=g1$width/72, height=g1$height/72) -grid.draw(g1) -} -} -\seealso{ - Other grob userlevel: \code{\link{arcTextGrob}}, - \code{\link{barbedGrob}}, \code{\link{borderGrob}}, - \code{\link{colorstripGrob}}, \code{\link{ellipseGrob}}, - \code{\link{interleaven}}, \code{\link{ngonGrob}}, - \code{\link{patternGrob}}, \code{\link{pixmapGrob}}, - \code{\link{rpatternGrob}}, \code{\link{stextGrob}}, - \code{\link{tableGrob}}, \code{\link{virtualGrob}} -} - diff -Nru r-cran-gridextra-0.9-1/man/ellipseGrob.Rd r-cran-gridextra-2.0.0/man/ellipseGrob.Rd --- r-cran-gridextra-0.9-1/man/ellipseGrob.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/ellipseGrob.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -\name{ellipseGrob} -\alias{ellipseGrob} -\alias{grid.ellipse} -\title{ellipseGrob} -\usage{ - ellipseGrob(x, y, size = 1, angle = rep(pi/2, length(x)), - ar = 1, gp = gpar(colour = "grey50", fill = "grey90"), - default.units = "native", size.units = "mm") -} -\arguments{ - \item{x}{x unit} - - \item{y}{y unit} - - \item{size}{size} - - \item{angle}{angle} - - \item{ar}{aspec ratio} - - \item{gp}{gpar} - - \item{default.units}{default units} - - \item{size.units}{size units} -} -\value{ - grob -} -\description{ - an ellipse grob -} -\examples{ -g = ellipseGrob(1:10/11,1:10/11,size=5,ar=1:5,angle=rnorm(10), - def="npc", gp=gpar(fill=grey(1:10/11))) -grid.draw(g) -} -\seealso{ - Other grob userlevel: \code{\link{arcTextGrob}}, - \code{\link{barbedGrob}}, \code{\link{borderGrob}}, - \code{\link{colorstripGrob}}, \code{\link{ebimageGrob}}, - \code{\link{interleaven}}, \code{\link{ngonGrob}}, - \code{\link{patternGrob}}, \code{\link{pixmapGrob}}, - \code{\link{rpatternGrob}}, \code{\link{stextGrob}}, - \code{\link{tableGrob}}, \code{\link{virtualGrob}} -} - diff -Nru r-cran-gridextra-0.9-1/man/expand.arguments.Rd r-cran-gridextra-2.0.0/man/expand.arguments.Rd --- r-cran-gridextra-0.9-1/man/expand.arguments.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/expand.arguments.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,21 +0,0 @@ -\name{expand.arguments} -\alias{expand.arguments} -\alias{pchlist} -\alias{rectii} -\alias{textii} -\alias{updatelist} -\title{expand.arguments} -\usage{ - expand.arguments(...) -} -\arguments{ - \item{...}{arguments} -} -\value{ - ... -} -\description{ - expand a list of arguments to full length (and misc. - undocumented functions) -} - diff -Nru r-cran-gridextra-0.9-1/man/gridExtra-package.Rd r-cran-gridextra-2.0.0/man/gridExtra-package.Rd --- r-cran-gridextra-0.9-1/man/gridExtra-package.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/gridExtra-package.Rd 2015-07-14 08:01:30.000000000 +0000 @@ -1,19 +1,21 @@ +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/gridExtra-package.r \docType{package} \name{gridExtra-package} \alias{gridExtra} \alias{gridExtra-package} -\title{misc. high-level functions for Grid graphics} +\title{Miscellaneous Functions for "Grid" Graphics} \description{ - functions for Grid graphics +Provides a number of user-level functions to work with "grid" graphics, notably to arrange multiple grid-based plots on a page, and draw tables. } \author{ - baptiste Auguie \email{baptiste.auguie@gmail.com} +baptiste Auguie \email{baptiste.auguie@gmail.com} } \references{ - R Graphics by Paul Murrell, ggplot2 source code +R Graphics by Paul Murrell (Chapman & Hall/CRC, August 2005) } \seealso{ - \code{\link{Grid}} +\code{\link{Grid}} } \keyword{packagelibrary} diff -Nru r-cran-gridextra-0.9-1/man/interleaven.Rd r-cran-gridextra-2.0.0/man/interleaven.Rd --- r-cran-gridextra-0.9-1/man/interleaven.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/interleaven.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,34 +0,0 @@ -\name{interleaven} -\alias{interleaven} -\title{interleaven} -\usage{ - interleaven(x = letters[1:3], y = 1:12, n = 4) -} -\arguments{ - \item{x}{vector} - - \item{y}{vector} - - \item{n}{integer} -} -\value{ - a vector -} -\description{ - mix two vectors -} -\examples{ -interleaven(replicate(3, rectGrob(), simplify=FALSE), replicate(12, virtualGrob, simplify=FALSE), 4) -} -\seealso{ - \code{rep}, \code{ggplot2:interleave} - - Other grob userlevel: \code{\link{arcTextGrob}}, - \code{\link{barbedGrob}}, \code{\link{borderGrob}}, - \code{\link{colorstripGrob}}, \code{\link{ebimageGrob}}, - \code{\link{ellipseGrob}}, \code{\link{ngonGrob}}, - \code{\link{patternGrob}}, \code{\link{pixmapGrob}}, - \code{\link{rpatternGrob}}, \code{\link{stextGrob}}, - \code{\link{tableGrob}}, \code{\link{virtualGrob}} -} - diff -Nru r-cran-gridextra-0.9-1/man/marrangeGrob.Rd r-cran-gridextra-2.0.0/man/marrangeGrob.Rd --- r-cran-gridextra-0.9-1/man/marrangeGrob.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/marrangeGrob.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,52 +0,0 @@ -\name{marrangeGrob} -\alias{marrangeGrob} -\alias{print.arrangelist} -\title{marrangeGrob} -\usage{ - marrangeGrob(..., as.table = FALSE, clip = TRUE, - top = quote(paste("page", g, "of", pages)), - bottom = NULL, left = NULL, right = NULL) -} -\arguments{ - \item{...}{grobs} - - \item{as.table}{see \link{arrangeGrob}} - - \item{clip}{see \link{arrangeGrob}} - - \item{top}{see \link{arrangeGrob}} - - \item{bottom}{see \link{arrangeGrob}} - - \item{left}{see \link{arrangeGrob}} - - \item{right}{see \link{arrangeGrob}} -} -\value{ - a list of class arrangelist -} -\description{ - Interface to arrangeGrob that can dispatch on multiple - pages -} -\details{ - If the layout specifies both nrow and ncol, the list of - grobs can be split in multiple pages. Interactive devices - print open new windows, whilst non-interactive devices - such as pdf call grid.newpage() between the drawings. -} -\examples{ -\dontrun{ -require(ggplot2) -pl <- lapply(1:11, function(.x) qplot(1:10,rnorm(10), main=paste("plot",.x))) -ml <- do.call(marrangeGrob, c(pl, list(nrow=2, ncol=2))) -## interactive use; open new devices -ml -## non-interactive use, multipage pdf -ggsave("multipage.pdf", ml) -} -} -\author{ - baptiste Auguie -} - diff -Nru r-cran-gridextra-0.9-1/man/ngonGrob.Rd r-cran-gridextra-2.0.0/man/ngonGrob.Rd --- r-cran-gridextra-0.9-1/man/ngonGrob.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/ngonGrob.Rd 2015-07-13 22:40:24.000000000 +0000 @@ -1,55 +1,98 @@ +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/ngonGrob.r \name{ngonGrob} +\alias{ellipseGrob} +\alias{grid.ellipse} \alias{grid.ngon} \alias{ngonGrob} -\title{ngonGrob} +\alias{polygon_regular} +\title{Regular polygon grob} \usage{ - ngonGrob(x, y, sides = 5, size = 1, - angle = rep(pi/2, length(x)), ar = rep(1, length(x)), - gp = gpar(colour = "grey50", fill = "grey90", linejoin = "mitre"), - units.def = "native", units.size = "mm") +ngonGrob(x, y, n = 5, size = 5, phase = pi/2, angle = 0, rho = 1, + gp = gpar(colour = "black", fill = NA, linejoin = "mitre"), ..., + position.units = "npc", size.units = "mm") + +grid.ngon(...) + +ellipseGrob(x, y, size = 5, angle = pi/4, rho = 1, n = 50, + gp = gpar(colour = "black", fill = NA, linejoin = "mitre"), ..., + position.units = "npc", size.units = "mm") + +grid.ellipse(...) + +polygon_regular(n = 5, phase = 0) } \arguments{ - \item{x}{x unit} +\item{x}{x unit} + +\item{y}{y unit} + +\item{n}{number of vertices} - \item{y}{y unit} +\item{size}{radius of circumscribing circle} - \item{sides}{sides} +\item{phase}{angle in radians of first point relative to x axis} - \item{size}{size} +\item{angle}{angle of polygon in radians} - \item{angle}{angle} +\item{rho}{aspect ratio} - \item{ar}{ar} +\item{gp}{gpar} - \item{units.def}{units.def} +\item{...}{further parameters passed to polygonGrob} - \item{units.size}{units.size} +\item{position.units}{default units for the positions} - \item{gp}{gpar} +\item{size.units}{grid units for the sizes} } \value{ - grob +grob } \description{ - regular polygon grob +Regular polygons with optional rotation, stretching, and aesthetic attributes } +\section{Functions}{ +\itemize{ +\item \code{ngonGrob}: return a polygon grob + +\item \code{grid.ngon}: draw a polygon grob on the current device + +\item \code{ellipseGrob}: return an ellipse grob + +\item \code{grid.ellipse}: draw an ellipse grob + +\item \code{polygon_regular}: return the x,y coordinates of a regular polygon inscribed in the unit circle +}} \examples{ -pushViewport(dataViewport(0:1, 0:1, width=unit(2, "cm"), height=unit(2, "cm"))) +library(grid) +N <- 5 +xy <- polygon_regular(N)*2 + +# draw multiple polygons +g <- ngonGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), + unit(xy[,2],"cm") + unit(0.5,"npc"), + n = seq_len(N) + 2, gp=gpar(fill=1:N)) + +grid.newpage() +grid.draw(g) + +# rotated and stretched +g2 <- ngonGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), + unit(xy[,2],"cm") + unit(0.5,"npc"), + n = seq_len(N) + 2, rho = seq_len(N), + phase = 0, angle=pi/(seq_len(N)+2), + size=1:N+5) + +grid.newpage() +grid.draw(g2) + +# ellipse +g3 <- ellipseGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), + unit(xy[,2],"cm") + unit(0.5,"npc"), + angle=-2*seq(0,N-1)*pi/5+pi/2, + size=5, rho=1/3) -xy <- polygon.regular(6, TRUE) -grid.ngon(0.5, 0.5, 6, 10, units.size="mm") -for(ii in 1:NROW(xy)){ - grid.ngon(xy[ii, 1]+0.5, xy[ii, 2]+0.5, 6, 10, units.size="mm") -} -upViewport() -} -\seealso{ - Other grob userlevel: \code{\link{arcTextGrob}}, - \code{\link{barbedGrob}}, \code{\link{borderGrob}}, - \code{\link{colorstripGrob}}, \code{\link{ebimageGrob}}, - \code{\link{ellipseGrob}}, \code{\link{interleaven}}, - \code{\link{patternGrob}}, \code{\link{pixmapGrob}}, - \code{\link{rpatternGrob}}, \code{\link{stextGrob}}, - \code{\link{tableGrob}}, \code{\link{virtualGrob}} +grid.newpage() +grid.draw(g3) } diff -Nru r-cran-gridextra-0.9-1/man/patternGrob.Rd r-cran-gridextra-2.0.0/man/patternGrob.Rd --- r-cran-gridextra-0.9-1/man/patternGrob.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/patternGrob.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,72 +0,0 @@ -\name{patternGrob} -\alias{drawDetails.pattern} -\alias{grid.pattern} -\alias{heightDetails.pattern} -\alias{patternGrob} -\alias{segments.pattern} -\alias{widthDetails.pattern} -\title{patternGrob} -\usage{ - patternGrob(x = unit(0.5, "npc"), y = unit(0.5, "npc"), - width = unit(1, "npc"), height = unit(1, "npc"), - pattern = 2, orientation = 45, - granularity = unit(5, "mm"), motif.col = "black", - motif.fill = NULL, motif.alpha = 1, motif.cex = 1, - pattern.offset = c(0, 0), default.units = "npc", - clip = TRUE, gp = gpar(fill = NA), ...) -} -\arguments{ - \item{x}{x unit} - - \item{y}{y unit} - - \item{width}{width} - - \item{height}{height} - - \item{pattern}{integer} - - \item{orientation}{orientation} - - \item{granularity}{unimplemented} - - \item{motif.col}{motif.col} - - \item{motif.fill}{motif.fill} - - \item{motif.alpha}{motif.alpha} - - \item{motif.cex}{motif.cex} - - \item{pattern.offset}{pattern.offset} - - \item{default.units}{default.units} - - \item{clip}{clip} - - \item{gp}{gp} - - \item{...}{additional params to the grob} -} -\value{ - grob of class pattern -} -\description{ - pattern grob -} -\examples{ -grid.pattern(x=seq(1/6, 5/6, length=6), width=unit(1/8,"npc"), height=unit(0.5,"npc"), - motif.width=unit(10, "mm"), pattern=c(1:6), orientation=45, motif.alpha=0.5, - motif.cex=c(1, 0.5), motif.col=1:2, motif.fill=NA, - gp=gpar(fill="blue", lwd=2, alpha=0.5), clip=TRUE) -} -\seealso{ - Other grob userlevel: \code{\link{arcTextGrob}}, - \code{\link{barbedGrob}}, \code{\link{borderGrob}}, - \code{\link{colorstripGrob}}, \code{\link{ebimageGrob}}, - \code{\link{ellipseGrob}}, \code{\link{interleaven}}, - \code{\link{ngonGrob}}, \code{\link{pixmapGrob}}, - \code{\link{rpatternGrob}}, \code{\link{stextGrob}}, - \code{\link{tableGrob}}, \code{\link{virtualGrob}} -} - diff -Nru r-cran-gridextra-0.9-1/man/pixmapGrob.Rd r-cran-gridextra-2.0.0/man/pixmapGrob.Rd --- r-cran-gridextra-0.9-1/man/pixmapGrob.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/pixmapGrob.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ -\name{pixmapGrob} -\alias{pixmapGrob} -\title{create a grob from pixmap object} -\usage{ - pixmapGrob(pic, x = 0.5, y = 0.5, scale = 1, - raster = FALSE, angle = 0, vp = NULL, ...) -} -\arguments{ - \item{pic}{pixmap object} - - \item{x}{x unit} - - \item{y}{y unit} - - \item{scale}{scale} - - \item{raster}{raster} - - \item{angle}{angle} - - \item{vp}{viewport} - - \item{...}{optional grob parameters, passed to imageGrob - or rasterGrob} -} -\value{ - a gTree of class 'pixmap', with natural width and height - in points -} -\description{ - create a grob from pixmap object -} -\details{ - Very primitive function, using RGraphics' imageGrob or - rasterGrob (R>=2.11) -} -\examples{ -library(pixmap) -library(RGraphics) -x <- read.pnm(system.file("pictures/logo.ppm", package="pixmap")[1]) -g1 <- pixmapGrob(x) -dev.new(width=g1$width/72, height=g1$height/72) -grid.draw(g1) -} -\seealso{ - Other grob userlevel: \code{\link{arcTextGrob}}, - \code{\link{barbedGrob}}, \code{\link{borderGrob}}, - \code{\link{colorstripGrob}}, \code{\link{ebimageGrob}}, - \code{\link{ellipseGrob}}, \code{\link{interleaven}}, - \code{\link{ngonGrob}}, \code{\link{patternGrob}}, - \code{\link{rpatternGrob}}, \code{\link{stextGrob}}, - \code{\link{tableGrob}}, \code{\link{virtualGrob}} -} - diff -Nru r-cran-gridextra-0.9-1/man/polygon1.Rd r-cran-gridextra-2.0.0/man/polygon1.Rd --- r-cran-gridextra-0.9-1/man/polygon1.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/polygon1.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ -\name{polygon1} -\alias{polygon1} -\alias{polygon2} -\title{polygon1} -\usage{ - polygon1(n = 5, ang = 0, ...) -} -\arguments{ - \item{n}{integer} - - \item{ang}{numeric angle} - - \item{...}{unused} -} -\value{ - a data.frame -} -\description{ - compute vertices of a convex polygon -} -\examples{ -polygon2(5) -} - diff -Nru r-cran-gridextra-0.9-1/man/polygon.regular.Rd r-cran-gridextra-2.0.0/man/polygon.regular.Rd --- r-cran-gridextra-0.9-1/man/polygon.regular.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/polygon.regular.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,30 +0,0 @@ -\name{polygon.regular} -\alias{polygon.regular} -\title{polygon.regular} -\usage{ - polygon.regular(sides = 4, scale.area = TRUE, - star = FALSE) -} -\arguments{ - \item{sides}{int} - - \item{scale.area}{logical} - - \item{star}{logical} -} -\value{ - a data.frame -} -\description{ - compute vertices of a polygon -} -\examples{ -polygon.regular(5) -} -\references{ - ngon from the 'maptree' package -} -\seealso{ - \code{star} -} - diff -Nru r-cran-gridextra-0.9-1/man/polygon.star.Rd r-cran-gridextra-2.0.0/man/polygon.star.Rd --- r-cran-gridextra-0.9-1/man/polygon.star.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/polygon.star.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,23 +0,0 @@ -\name{polygon.star} -\alias{polygon.star} -\title{polygon.star} -\usage{ - polygon.star(n = 4, adj = pi/2, r = 1) -} -\arguments{ - \item{n}{int} - - \item{adj}{numeric angle} - - \item{r}{radius} -} -\value{ - a data.frame -} -\description{ - compute vertices of a starred polygon -} -\examples{ -polygon.star(5) -} - diff -Nru r-cran-gridextra-0.9-1/man/read.tiff.Rd r-cran-gridextra-2.0.0/man/read.tiff.Rd --- r-cran-gridextra-0.9-1/man/read.tiff.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/read.tiff.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,19 +0,0 @@ -\name{read.tiff} -\alias{as.raster.pixmapRGB} -\alias{read.tiff} -\title{read tiff files with pixmap} -\usage{ - read.tiff(con, ...) -} -\arguments{ - \item{con}{connection} - - \item{...}{unused} -} -\value{ - ... -} -\description{ - read tiff files with pixmap -} - diff -Nru r-cran-gridextra-0.9-1/man/rowMax.units.Rd r-cran-gridextra-2.0.0/man/rowMax.units.Rd --- r-cran-gridextra-0.9-1/man/rowMax.units.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/rowMax.units.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,23 +0,0 @@ -\name{rowMax.units} -\alias{colMax.units} -\alias{rowMax.units} -\title{rowMax.units} -\usage{ - rowMax.units(u, nrow) -} -\arguments{ - \item{u}{list of units} - - \item{nrow}{nrow} -} -\value{ - a vector of units -} -\description{ - calculates the max of a list of units arranged in a - matrix -} -\seealso{ - \code{unit.c}, \code{unit} -} - diff -Nru r-cran-gridextra-0.9-1/man/rpatternGrob.Rd r-cran-gridextra-2.0.0/man/rpatternGrob.Rd --- r-cran-gridextra-0.9-1/man/rpatternGrob.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/rpatternGrob.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,65 +0,0 @@ -\name{rpatternGrob} -\alias{drawDetails.rpattern} -\alias{grid.rpattern} -\alias{heightDetails.rpattern} -\alias{rpatternGrob} -\alias{tile.motif} -\alias{widthDetails.rpattern} -\title{rpatternGrob} -\usage{ - rpatternGrob(x = unit(0.5, "npc"), y = unit(0.5, "npc"), - width = unit(1, "npc"), height = unit(1, "npc"), - motif = matrix("white"), AR = 1, - motif.width = unit(5, "mm"), - motif.height = AR * motif.width, - pattern.offset = c(0, 0), default.units = "npc", - clip = TRUE, gp = gpar(fill = NA), ...) -} -\arguments{ - \item{x}{x unit} - - \item{y}{y unit} - - \item{width}{width} - - \item{height}{height} - - \item{motif}{motif} - - \item{AR}{AR} - - \item{motif.width}{motif.width} - - \item{motif.height}{motif.height} - - \item{pattern.offset}{pattern.offset} - - \item{default.units}{default.units} - - \item{clip}{clip} - - \item{gp}{gp} - - \item{...}{additional params passed to the grob} -} -\value{ - grob of class rpattern -} -\description{ - rectangular grob with raster fill pattern -} -\examples{ -.lines45 <- matrix("white", ncol=100, nrow=100) -diag(.lines45) <- "black" -grid.rpattern(motif=.lines45) -} -\seealso{ - Other grob userlevel: \code{\link{arcTextGrob}}, - \code{\link{barbedGrob}}, \code{\link{borderGrob}}, - \code{\link{colorstripGrob}}, \code{\link{ebimageGrob}}, - \code{\link{ellipseGrob}}, \code{\link{interleaven}}, - \code{\link{ngonGrob}}, \code{\link{patternGrob}}, - \code{\link{pixmapGrob}}, \code{\link{stextGrob}}, - \code{\link{tableGrob}}, \code{\link{virtualGrob}} -} - diff -Nru r-cran-gridextra-0.9-1/man/stextGrob.Rd r-cran-gridextra-2.0.0/man/stextGrob.Rd --- r-cran-gridextra-0.9-1/man/stextGrob.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/stextGrob.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,64 +0,0 @@ -\name{stextGrob} -\alias{grid.stext} -\alias{stextGrob} -\title{stextGrob} -\usage{ - stextGrob(label, r = 0.1, x = unit(0.5, "npc"), - y = unit(0.5, "npc"), just = "centre", hjust = NULL, - vjust = NULL, rot = 0, check.overlap = FALSE, - default.units = "npc", name = NULL, gp = gpar(), - vp = NULL) -} -\arguments{ - \item{label}{see textGrob} - - \item{r}{blur radius} - - \item{x}{see textGrob} - - \item{y}{see textGrob} - - \item{just}{see textGrob} - - \item{hjust}{see textGrob} - - \item{vjust}{see textGrob} - - \item{rot}{see textGrob} - - \item{check.overlap}{see textGrob} - - \item{default.units}{see textGrob} - - \item{name}{see textGrob} - - \item{gp}{see textGrob} - - \item{vp}{see textGrob} -} -\value{ - gTree -} -\description{ - shadow text -} -\details{ - adds a blurred white version of a label below the text -} -\examples{ -grid.rect(gp=gpar(fill="grey")) -grid.stext("test") -} -\author{ - Baptiste Auguie -} -\seealso{ - Other grob userlevel: \code{\link{arcTextGrob}}, - \code{\link{barbedGrob}}, \code{\link{borderGrob}}, - \code{\link{colorstripGrob}}, \code{\link{ebimageGrob}}, - \code{\link{ellipseGrob}}, \code{\link{interleaven}}, - \code{\link{ngonGrob}}, \code{\link{patternGrob}}, - \code{\link{pixmapGrob}}, \code{\link{rpatternGrob}}, - \code{\link{tableGrob}}, \code{\link{virtualGrob}} -} - diff -Nru r-cran-gridextra-0.9-1/man/tableGrob.Rd r-cran-gridextra-2.0.0/man/tableGrob.Rd --- r-cran-gridextra-0.9-1/man/tableGrob.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/tableGrob.Rd 2015-07-14 08:59:17.000000000 +0000 @@ -1,145 +1,54 @@ +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/tableGrob.r \name{tableGrob} -\alias{arrangeTableGrobs} -\alias{drawDetails.table} \alias{grid.table} -\alias{heightDetails.table} -\alias{makeTableGrobs} \alias{tableGrob} -\alias{widthDetails.table} -\title{tableGrob} +\alias{ttheme_default} +\alias{ttheme_default,} +\alias{ttheme_minimal} +\title{Graphical display of a textual table} \usage{ - tableGrob(d, rows = rownames(d), cols = colnames(d), - parse = FALSE, show.rownames = TRUE, - show.colnames = TRUE, row.just = "center", - col.just = "center", core.just = "center", - separator = "white", show.box = FALSE, - show.vlines = FALSE, show.hlines = FALSE, - show.namesep = FALSE, show.csep = FALSE, - show.rsep = FALSE, equal.width = FALSE, - equal.height = FALSE, padding.h = unit(4, "mm"), - padding.v = unit(4, "mm"), gp = NULL, - gpar.coretext = gpar(col = "black", cex = 1), - gpar.coltext = gpar(col = "black", cex = 1, fontface = "bold"), - gpar.rowtext = gpar(col = "black", cex = 0.8, fontface = "italic"), - h.odd.alpha = 1, h.even.alpha = 1, v.odd.alpha = 1, - v.even.alpha = 1, - gpar.corefill = gpar(fill = "grey95", col = "white"), - gpar.rowfill = gpar(fill = "grey90", col = "white"), - gpar.colfill = gpar(fill = "grey90", col = "white"), - theme = NULL, ...) -} -\arguments{ - \item{d}{data.frame} - - \item{rows}{vector of row names} - - \item{cols}{vector of col names} - - \item{parse}{logical, parse labels as expressions} - - \item{row.just}{justification of labels} - - \item{col.just}{justification of labels} - - \item{core.just}{justification of labels} - - \item{separator}{colour of the border lines} - - \item{show.box}{logical box surrounding the table} - - \item{show.vlines}{logical vertical lines} - - \item{show.hlines}{logical horizontal lines} - - \item{show.namesep}{logical draw lines to separate - header(s)} - - \item{show.csep}{logical extend vert. separator to - colnames} - - \item{show.rsep}{logical extend vert. separator to - rownames} - - \item{equal.width}{logical} - - \item{equal.height}{logical} - - \item{padding.h}{unit of horizontal margin, per cell} +tableGrob(d, rows = rownames(d), cols = colnames(d), + theme = ttheme_default(), ...) - \item{padding.v}{unit of vertical margin, per cell} +grid.table(...) - \item{gpar.coretext}{gpar() for inner text} +ttheme_default(...) - \item{gpar.corefill}{gpar() for inner fill} - - \item{gpar.coltext}{gpar() for colnames text} - - \item{h.odd.alpha}{numeric transparency factor for odd - horizontal cells} - - \item{h.even.alpha}{numeric transparency factor for even - horizontal cells} - - \item{v.odd.alpha}{numeric transparency factor for odd - vertical cells} - - \item{v.even.alpha}{numeric transparency factor for even - vertical cells} - - \item{gpar.colfill}{gpar() for colnames fill} - - \item{gpar.rowtext}{gpar() for rownames text} - - \item{gpar.rowfill}{gpar() for rownames fill} - - \item{show.rownames}{logical} +ttheme_minimal(...) +} +\arguments{ +\item{d}{data.frame or matrix} - \item{show.colnames}{logical} +\item{rows}{optional vector to specify row names} - \item{gp}{gpar} +\item{cols}{optional vector to specify column names} - \item{theme}{theme (list of aesthetic elements)} +\item{theme}{list of theme parameters} - \item{...}{passed to grob} +\item{...}{further arguments to control the gtable} } \value{ - a grob of class table +a gtable } \description{ - create a list of text and fill grobs and calculates the - sizes for a table display +Create a gtable containing text grobs representing a character matrix } +\section{Functions}{ +\itemize{ +\item \code{tableGrob}: return a grob + +\item \code{grid.table}: draw a text table + +\item \code{ttheme_default}: default theme for text tables + +\item \code{ttheme_minimal}: minimalist theme for text tables +}} \examples{ -grid.table(head(iris), h.even.alpha=1, h.odd.alpha=1, v.even.alpha=0.5, v.odd.alpha=1) -grid.newpage() -grid.draw(tableGrob(head(iris, 10), name="test")) -e = expression(alpha,"testing very large width", hat(beta), integral(f(x)*dx, a, b), "abc") -grid.edit("test", cols=e, show.rownames=FALSE, rows=NULL, - gpar.corefill = gpar(fill="white", col=NA), - grep=TRUE, global=TRUE) - grid.newpage() - grid.draw(tableGrob(head(iris, 10), - show.csep=TRUE, show.rsep=TRUE, show.box=TRUE, separator="grey", name="test")) - grid.edit("test",gp=gpar(fontsize=8, lwd=2), equal.width=TRUE, grep=TRUE, global=TRUE) -# visualize themes -lg <- lapply(c("theme.blank", "theme.default", "theme.white", "theme.vertical", "theme.list", "theme.black"), - function(x) tableGrob(head(iris[, 1:3]), theme=get(x)())) +library(grid) +d <- head(iris, 3) +g <- tableGrob(d) grid.newpage() -do.call(grid.arrange, lg) -\dontrun{ -## timing: a bit slow due to repeated on-the-fly calculations -pdf("test2.pdf", height=50) -print(system.time( grid.table(iris)) ) # about 12s here -dev.off() -} -} -\seealso{ - Other grob userlevel: \code{\link{arcTextGrob}}, - \code{\link{barbedGrob}}, \code{\link{borderGrob}}, - \code{\link{colorstripGrob}}, \code{\link{ebimageGrob}}, - \code{\link{ellipseGrob}}, \code{\link{interleaven}}, - \code{\link{ngonGrob}}, \code{\link{patternGrob}}, - \code{\link{pixmapGrob}}, \code{\link{rpatternGrob}}, - \code{\link{stextGrob}}, \code{\link{virtualGrob}} +grid.draw(g) } diff -Nru r-cran-gridextra-0.9-1/man/theme.default.Rd r-cran-gridextra-2.0.0/man/theme.default.Rd --- r-cran-gridextra-0.9-1/man/theme.default.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/theme.default.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,23 +0,0 @@ -\name{theme.default} -\alias{theme.black} -\alias{theme.blank} -\alias{theme.default} -\alias{theme.grey} -\alias{theme.list} -\alias{theme.vertical} -\alias{theme.white} -\title{theme} -\usage{ - theme.default(...) -} -\arguments{ - \item{...}{optional params to overwrite the theme - defaults} -} -\value{ - theme -} -\description{ - themes for table grob -} - diff -Nru r-cran-gridextra-0.9-1/man/virtualGrob.Rd r-cran-gridextra-2.0.0/man/virtualGrob.Rd --- r-cran-gridextra-0.9-1/man/virtualGrob.Rd 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/man/virtualGrob.Rd 1970-01-01 00:00:00.000000000 +0000 @@ -1,32 +0,0 @@ -\docType{data} -\name{virtualGrob} -\alias{drawDetails.virtual} -\alias{grobHeight.virtual} -\alias{grobWidth.virtual} -\alias{heightDetails.virtual} -\alias{is.zero} -\alias{virtualGrob} -\alias{widthDetails.virtual} -\title{virtualGrob} -\format{List of 3 - $ name: chr "NULL" - $ gp : NULL - $ vp : NULL - - attr(*, "class")= chr [1:3] "virtual" "grob" "gDesc"} -\usage{ - virtualGrob -} -\description{ - zero grob borrowed from ggplot2 -} -\seealso{ - Other grob userlevel: \code{\link{arcTextGrob}}, - \code{\link{barbedGrob}}, \code{\link{borderGrob}}, - \code{\link{colorstripGrob}}, \code{\link{ebimageGrob}}, - \code{\link{ellipseGrob}}, \code{\link{interleaven}}, - \code{\link{ngonGrob}}, \code{\link{patternGrob}}, - \code{\link{pixmapGrob}}, \code{\link{rpatternGrob}}, - \code{\link{stextGrob}}, \code{\link{tableGrob}} -} -\keyword{datasets} - diff -Nru r-cran-gridextra-0.9-1/MD5 r-cran-gridextra-2.0.0/MD5 --- r-cran-gridextra-0.9-1/MD5 2012-08-09 05:38:06.000000000 +0000 +++ r-cran-gridextra-2.0.0/MD5 2015-07-14 18:40:38.000000000 +0000 @@ -1,48 +1,30 @@ -e50d374543161056ff2c4cc963e8e871 *DESCRIPTION -a510d4c7ba985cdf8bbca4a794c18c90 *NAMESPACE -8dda6de8896909769c89947e81db028c *NEWS -eddd2437925d368d65b945da079e9eea *R/arcText.r -e833e25e6cbcfc88147e3fe5100f0d23 *R/arrange.r -27e64cbfdf81082869be2cfbc74a9819 *R/barbedGrob.r -6f51476a46a01971c8a533b940d124e7 *R/borderGrob.r -89e04a98f17707619d29a45fc11910e7 *R/colorstripGrob.r -f7bde91d89f3c8e88da363cfaa76f528 *R/ebimage.r -2a4376ab67f7d5a6b611252d1a046804 *R/ellipseGrob.r -dfac18130b4e8e816509205b2904c260 *R/gridExtra-package.r -fe48c518bbda9969a0bb6a4673156e96 *R/grob-utils.r -f88195687bb2e541e3174787cb642dd0 *R/ngonGrob.r -67529feb697920aaa972d7eafd6b6e30 *R/patternGrob.r -df389200a49c4e98c31fe1e2f05f5cf7 *R/pixmap.r -68c54a0c45f1284259c027307205f6d5 *R/polygon.regular.r -2766c64e512512e793ec09ae5c0293f1 *R/rpattern.r -3a90cd169a5fa71fd245ac7c5da32746 *R/stextGrob.r -4609bee2bdd403f443db1a1b20dbfbd6 *R/tableGrob.r -d41d8cd98f00b204e9800998ecf8427e *README -2e30b1b53cae8f29aacd8ca8037706e3 *TODO -fb4f9c1862a715ea12a0e398cd086d67 *inst/test/expressions.r -ac6124e5cbaf4b2bf7684b9f49a1b7c0 *inst/test/tableGrob-grobnames.r -fbd8cccf4f8f14111e00a0096f5fb1b4 *inst/test/tableGrob2.r -fc2a079bca2ba895bdc8ae01ddd98505 *man/arcTextGrob.Rd -083db13c2b6e39241e7dcab214ef7ad0 *man/arrangeGrob.Rd -1b1d224d3f3f2e2bfa2d460da52f826a *man/barbedGrob.Rd -83aed133317fcb10973a5fe0155f8e76 *man/borderGrob.Rd -05f5bb8fc2f61317b12359ee3772466a *man/colorstripGrob.Rd -039f73e33b83ae3aa85b36ade704fa25 *man/ebimageGrob.Rd -c3cb8e0914a534323720065b8c671846 *man/ellipseGrob.Rd -9e6476008c06aa4ada193e13cb6cdaa0 *man/expand.arguments.Rd -9c715a56a0f23903b5c01f4154dd6e9a *man/gridExtra-package.Rd -cb296f2a255e859fa7f97a94d533903d *man/interleaven.Rd -e330fc3d04e5f5ea36c6d0d1e1852d58 *man/marrangeGrob.Rd -78aead2cf2b1805642a5bbf4b80ccb1a *man/ngonGrob.Rd -137b6baaed5f5eeadcd7189c7cae5a5b *man/patternGrob.Rd -185ff29d997ea65768b1f9b82356accc *man/pixmapGrob.Rd -c1b64ae6a4d472646f8052ff4cb859ab *man/polygon.regular.Rd -7d777e99278ba6011ecdf1c46bab5be9 *man/polygon.star.Rd -e77220978a9c18bbce76721f7d4a860e *man/polygon1.Rd -15843b492eab6bdf7ea89903296671a0 *man/read.tiff.Rd -5a095ced2907b83f87971118f14ee9aa *man/rowMax.units.Rd -53db01ccfdbf5fa32214045e5da38b07 *man/rpatternGrob.Rd -d8aa6d22cbcb50e26c2fa1179a343e3b *man/stextGrob.Rd -cf375bfe0c2e6eca93ac3d4878a481c2 *man/tableGrob.Rd -10f924d5b2c716369c6529e762664df9 *man/theme.default.Rd -80087314d20638c2b162f00aa2a33e84 *man/virtualGrob.Rd +170972406943f42756c9fa6ffc1e422f *DESCRIPTION +a7754e546ee14a98c5021dc4e6957a88 *NAMESPACE +7db5232c72d337ff3b2b9337906ecabb *R/arrangeGrob.r +22e6d58f19b3df08f6d7b740100035b1 *R/gridExtra-package.r +a141338e85da6557c82317af333108f9 *R/grob-utils.r +bd51a8b649a49a3ea5399f2a9279323f *R/ngonGrob.r +0394e29fdb36b8e28209880d117cd509 *R/tableGrob.r +0f791edfac076bcb24a3fb6932271d86 *README.md +62da238e97b31431264b3f20a43e891d *TODO +1fbbbb5a43659e082d472263a04c4035 *build/vignette.rds +e5ad57d16624d3c9bbe81483d42cfbd6 *inst/NEWS.md +975cac45b0dec63649eebc5f4af48051 *inst/doc/arrangeGrob.R +dde089703558e7754207fcf10c77a07d *inst/doc/arrangeGrob.html +971bfe5b59b8317dbfbbbbeadbf5744a *inst/doc/arrangeGrob.rmd +eb82672ccaa50856f92d457aee242332 *inst/doc/ngonGrob.R +10af0beb4250dfba6f484debdfcf1c64 *inst/doc/ngonGrob.html +9d209d89a159ec7a45cd1a5a8c71b6d6 *inst/doc/ngonGrob.rmd +b1e08e2fe8ada609fdf2cb11236d5c17 *inst/doc/tableGrob.R +5c78ff7b9e664d4acee408bfe84848eb *inst/doc/tableGrob.html +399b49ca8729645e640efb0e9a0545cd *inst/doc/tableGrob.rmd +618723bd19c005badd6924545e8b0d06 *inst/tests/testthat.r +1c6c2aa851549cbd04b6fa0f8f778f5c *inst/tests/testthat/test-arrangeGrob.R +707773b71f1e28d5e38031757aa2a1d5 *inst/tests/testthat/test-tableGrob.R +7648283d17c4e6b5331fb1f564308443 *man/arrangeGrob.Rd +486bff38ccd3fcb185787160d0a33dc5 *man/gridExtra-package.Rd +7d9ad03456af2729afed995b79bc18e6 *man/ngonGrob.Rd +74d71f2d764b6025c5fe88bd1b4e0423 *man/tableGrob.Rd +971bfe5b59b8317dbfbbbbeadbf5744a *vignettes/arrangeGrob.rmd +9d209d89a159ec7a45cd1a5a8c71b6d6 *vignettes/ngonGrob.rmd +399b49ca8729645e640efb0e9a0545cd *vignettes/tableGrob.rmd diff -Nru r-cran-gridextra-0.9-1/NAMESPACE r-cran-gridextra-2.0.0/NAMESPACE --- r-cran-gridextra-0.9-1/NAMESPACE 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/NAMESPACE 2015-07-14 01:13:52.000000000 +0000 @@ -1,59 +1,24 @@ -export(arcTextGrob) +# Generated by roxygen2 (4.1.1): do not edit by hand + +S3method(drawDetails,lattice) +S3method(grid.draw,arrangelist) +S3method(print,arrangelist) export(arrangeGrob) -export(as.raster.pixmapRGB) -export(barbedGrob) -export(borderGrob) -export(colMax.units) -export(colorstripGrob) -export(drawDetails.lattice) -export(drawDetails.pattern) -export(drawDetails.rpattern) -export(drawDetails.table) -export(drawDetails.virtual) -export(ebimageGrob) export(ellipseGrob) -export(grid.arcText) export(grid.arrange) -export(grid.barbed) -export(grid.border) -export(grid.colorstrip) export(grid.ellipse) export(grid.ngon) -export(grid.pattern) -export(grid.rpattern) -export(grid.stext) export(grid.table) -export(grobHeight.virtual) -export(grobWidth.virtual) -export(heightDetails.pattern) -export(heightDetails.rpattern) -export(heightDetails.table) -export(heightDetails.virtual) -export(interleaven) -export(latticeGrob) export(marrangeGrob) export(ngonGrob) -export(patternGrob) -export(pixmapGrob) -export(polygon.regular) -export(polygon.star) -export(polygon2) -export(print.arrange) -export(print.arrangelist) -export(read.tiff) -export(rowMax.units) -export(rpatternGrob) -export(stextGrob) +export(polygon_regular) export(tableGrob) -export(theme.black) -export(theme.blank) -export(theme.default) -export(theme.list) -export(theme.vertical) -export(theme.white) -export(virtualGrob) -export(widthDetails.pattern) -export(widthDetails.rpattern) -export(widthDetails.table) -export(widthDetails.virtual) +export(ttheme_default) +export(ttheme_minimal) import(grid) +import(gtable) +importFrom(grDevices,dev.interactive) +importFrom(grDevices,dev.new) +importFrom(grDevices,n2mfrow) +importFrom(graphics,plot) +importFrom(utils,modifyList) diff -Nru r-cran-gridextra-0.9-1/NEWS r-cran-gridextra-2.0.0/NEWS --- r-cran-gridextra-0.9-1/NEWS 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/NEWS 1970-01-01 00:00:00.000000000 +0000 @@ -1,22 +0,0 @@ -gridExtra 0.9 (2012-01-06) ----------------------------------------- - -FIX - -* dependencies in examples, imports and exports - -NEW - -* multipage output and ggsave support for grid.arrange - - -gridExtra 0.8.5 (2011-10-26) ----------------------------------------- - -FIX - -* removed LazyLoad, deprecated in R>=2.14 - -NEW - -* stextGrob text with a background \ No newline at end of file diff -Nru r-cran-gridextra-0.9-1/R/arcText.r r-cran-gridextra-2.0.0/R/arcText.r --- r-cran-gridextra-0.9-1/R/arcText.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/arcText.r 1970-01-01 00:00:00.000000000 +0000 @@ -1,63 +0,0 @@ -##' place text labels on a circle and display relations with arcs -##' -##' @aliases arcTextGrob grid.arcText -##' @param x x unit -##' @param y y unit -##' @param labels text labels -##' @param links integer vector -##' @param default.units default units -##' @param gp gpar -##' @param ... additional params (unused) -##' @return grob -##' @export -##' @family grob userlevel -##' -##' @examples -##' library(grid) -##' set.seed(1234) -##' grid.newpage() -##' grid.arcText() - -arcTextGrob <- function(x=unit(0.5, "npc"), y=unit(0.5, "npc"), - labels=LETTERS, - links=sample(seq_along(labels), 50, replace = TRUE), - default.units="npc", - gp=gpar(), ...) - { - - ## circle - full.height <- sum(stringHeight(labels)) - radius <- 1.2 /(2*pi) * full.height - g1 <- circleGrob(0.5, 0.5, r=radius, default.units="npc", gp=gpar(col=NA)) - - ## text labels - n <- length(labels) - ang <- seq(0, n-1) * 2 * pi/n - - radius.npc <- convertUnit(radius, "npc", valueOnly=TRUE) - coords <- data.frame(x=0.5+radius.npc*cos(ang), y=0.5+radius.npc*sin(ang)) - g2 <- textGrob(labels, x=coords$x , y=coords$y , rot=ang*180/pi, default.units="npc", hjust=0) - - ## connecting pairs - - xm <- matrix(coords$x[links], ncol=2, byrow=TRUE) - ym <- matrix(coords$y[links], ncol=2, byrow=TRUE) - - ## find out which pairs are not in trigo order - ## and swap them - swap <- as.logical(sign((xm[, 1]-0.5)*(ym[, 2]-0.5) - (xm[, 2]-0.5)*(ym[, 1]-0.5)) + 1) - xm[swap, ] <- rev(xm[swap]) - ym[swap, ] <- rev(ym[swap]) - - g3 <- do.call(gList, mapply(curveGrob, x1=xm[, 1], y1=ym[, 1], x2=xm[, 2], y2=ym[, 2], - ncp=8, curvature=0.4, square=FALSE, SIMPLIFY=FALSE)) - - gTree(children=gList(g1, g2, g3), - outer.radius=convertUnit(radius, "npc") + - convertUnit(max(stringWidth(labels)), "npc")) - } - - -##' @export -grid.arcText <- function(...) - grid.draw(arcTextGrob(...)) diff -Nru r-cran-gridextra-0.9-1/R/arrangeGrob.r r-cran-gridextra-2.0.0/R/arrangeGrob.r --- r-cran-gridextra-0.9-1/R/arrangeGrob.r 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/arrangeGrob.r 2015-07-14 08:56:08.000000000 +0000 @@ -0,0 +1,261 @@ +##' @aliases grid.arrange arrangeGrob marrangeGrob +##' @title Arrange multiple grobs on a page +##' @description Set up a gtable layout to place multiple grobs on a page +##' @describeIn arrangeGrob return a grob without drawing +##' @param ... grobs, gtables, ggplot or trellis objects +##' @param grobs list of grobs +##' @param top optional string, or grob +##' @param bottom optional string, or grob +##' @param left optional string, or grob +##' @param right optional string, or grob +##' @param padding unit of length one, margin around annotations +##' @param as.table logical: bottom-left to top-right or top-left to bottom-right +##' @param layout_matrix optional layout +##' @param name argument of gtable +##' @param respect argument of gtable +##' @param clip argument of gtable +##' @param nrow argument of gtable +##' @param ncol argument of gtable +##' @param widths argument of gtable +##' @param heights argument of gtable +##' @param vp viewport +##' @return arrangeGrob returns a gtable +##' @import gtable +##' @import grid +##' @importFrom grDevices n2mfrow +##' @export +##' +##' @examples +##' library(grid) +##' grid.arrange(rectGrob(), rectGrob()) +arrangeGrob <- function(..., grobs=list(...), + layout_matrix, + vp=NULL, name = "arrange", + as.table=TRUE, + respect = FALSE, clip = "off", + nrow=NULL, ncol=NULL, + widths = NULL, heights = NULL, + top = NULL, bottom = NULL, + left = NULL, right = NULL, + padding = unit(0.5,"line")){ + + n <- length(grobs) + + ## logic for the layout + # if nrow/ncol supplied, honour this + # if not, use length of widths/heights, if supplied + # if nothing supplied, work out sensible defaults + + ## nothing to be done but check inconsistency + if (!is.null(ncol) && !is.null(widths)){ + stopifnot(length(widths) == ncol) + } + if (!is.null(nrow) && !is.null(heights)){ + stopifnot(length(heights) == nrow) + } + ## use widths/heights if supplied + if (is.null(ncol) && !is.null(widths)){ + ncol <- length(widths) + } + if (is.null(nrow) && !is.null(heights)){ + nrow <- length(heights) + } + ## work out the missing one + if(is.null(nrow) && !is.null(ncol)) { + nrow <- ceiling(n/ncol) + } + if(is.null(ncol) && !is.null(nrow)) { + ncol <- ceiling(n/nrow) + } + + ## it may happen that sufficient info was passed, + ## but incompatible with number of grobs (fewer cells) + stopifnot(nrow*ncol >= n) + + ## last case: nothing exists + if(is.null(nrow) && is.null(ncol) && + is.null(widths) && is.null(heights)) + { + nm <- grDevices::n2mfrow(n) + nrow = nm[1] + ncol = nm[2] + } + + ## debugging + # message("nrow:", nrow, " ncol:", ncol) + + ## conversions + inherit.ggplot <- unlist(lapply(grobs, inherits, what="ggplot")) + inherit.trellis <- unlist(lapply(grobs, inherits, what="trellis")) + if(any(inherit.ggplot)) { + stopifnot(requireNamespace("ggplot2", quietly = TRUE)) + toconv <- which(inherit.ggplot) + grobs[toconv] <- lapply(grobs[toconv], ggplot2::ggplotGrob) + } + if(any(inherit.trellis)) { + stopifnot(requireNamespace("lattice", quietly = TRUE)) + toconv <- which(inherit.trellis) + grobs[toconv] <- lapply(grobs[toconv], latticeGrob) + } + + if(missing(layout_matrix)){ # default layout: one cell for each grob + + positions <- expand.grid(t = seq_len(nrow), + l = seq_len(ncol)) + positions$b <- positions$t + positions$r <- positions$l + if(as.table) # fill table by rows + positions <- positions[order(positions$t),] + + positions <- positions[seq_along(grobs), ] # n might be < ncol*nrow + + } else { # a layout was supplied + + cells <- sort(unique(as.vector(layout_matrix))) + ## left/right/top/bottom borders for given id + range_cell <- function(ii){ + ind <- which(layout_matrix == ii, arr.ind=TRUE) + c(l=min(ind[,"col"]), + r=max(ind[,"col"]), + t=min(ind[,"row"]), + b=max(ind[,"row"])) + } + positions <- data.frame(do.call(rbind, lapply(cells, range_cell))) + + ncol <- max(positions$r) + nrow <- max(positions$b) + } + + ## sizes + if(is.null(widths)) widths <- unit(rep(1, ncol), "null") + if(is.null(heights)) heights <- unit(rep(1,nrow), "null") + + ## lazy size specification as relative numbers + if (!is.unit(widths)) widths <- unit(widths, "null") + if (!is.unit(heights)) heights <- unit(heights, "null") + + ## build the gtable, similar steps to gtable_matrix + gt <- gtable(name=name, + respect = respect, + heights = heights, + widths = widths, + vp=vp) + + gt <- gtable_add_grob(gt, grobs, + t = positions$t, + b = positions$b, + l = positions$l, + r = positions$r, + z = seq_along(grobs), + clip = clip) + + ## titles given as strings are converted to text grobs + if(is.character(top)){ + top <- textGrob(top) + } + if(is.grob(top)){ + h <- grobHeight(top) + padding + gt <- gtable_add_rows(gt, heights=h, 0) + gt <- gtable_add_grob(gt, top, t=1, l=1, r=ncol(gt), z=Inf, + clip = clip) + } + if(is.character(bottom)){ + bottom <- textGrob(bottom) + } + if(is.grob(bottom)){ + h <- grobHeight(bottom) + padding + gt <- gtable_add_rows(gt, heights = h, -1) + gt <- gtable_add_grob(gt, bottom, + t=nrow(gt), l=1, r=ncol(gt), z=Inf, + clip = clip) + } + if(is.character(left)){ + left <- textGrob(left, rot = 90) + } + if(is.grob(left)){ + w <- grobWidth(left) + padding + gt <- gtable_add_cols(gt, widths=w, 0) + gt <- gtable_add_grob(gt, left, t=1, b=nrow(gt), + l=1, r=1, z=Inf, + clip = clip) + } + if(is.character(right)){ + right <- textGrob(right, rot = -90) + } + if(is.grob(right)){ + w <- grobWidth(right) + padding + gt <- gtable_add_cols(gt, widths=w, -1) + gt <- gtable_add_grob(gt, right, + t=1, b=nrow(gt), + l=ncol(gt), r=ncol(gt), z=Inf, + clip = clip) + } + + gt +} + +##' @describeIn arrangeGrob draw on the current device +##' @param newpage open a new page +##' @inheritParams arrangeGrob +##' @export +grid.arrange <- function(..., newpage=TRUE){ + if(newpage) grid.newpage() + g <- arrangeGrob(...) + grid.draw(g) + invisible(g) +} + + +##' @describeIn arrangeGrob interface to arrangeGrob that can dispatch on multiple pages +##' @details Using marrangeGrob, if the layout specifies both nrow and ncol, the list of grobs can be split into multiple pages. On interactive devices print open new windows, whilst non-interactive devices such as pdf call grid.newpage() between the drawings. +##' @return marrangeGrobm returns a list of class arrangelist +##' @export +##' @examples +##' \dontrun{ +##' library(ggplot2) +##' pl <- lapply(1:11, function(.x) qplot(1:10,rnorm(10), main=paste("plot",.x))) +##' ml <- marrangeGrob(pl, nrow=2, ncol=2) +##' ## interactive use; open new devices +##' ml +##' ## non-interactive use, multipage pdf +##' ggsave("multipage.pdf", ml) +##' } +marrangeGrob <- function(grobs, ncol, nrow, ..., + top = quote(paste("page", g, "of", pages))){ + + n <- length(grobs) + nlay <- nrow*ncol + pages <- n %/% nlay + as.logical(n %% nlay) + + groups <- split(seq_along(grobs), + gl(pages, nlay, n)) + + pl <- vector(mode = "list", length = pages) + + for(page in seq_along(groups)){ + g <- page + params <- modifyList(list(...), list(top=eval(top), + nrow=nrow, ncol=ncol)) + pl[[g]] <- do.call(arrangeGrob, c(grobs[groups[[g]]], params)) + } + + class(pl) <- c("arrangelist", class(pl)) + pl + +} + +##' @noRd +##' @importFrom grDevices dev.interactive dev.new +##' @export +grid.draw.arrangelist = function(x, ...) lapply(x, function(.x) { + if(dev.interactive()) dev.new() else grid.newpage() + grid.draw(.x) +}, ...) + +##' @noRd +##' @importFrom grDevices dev.interactive dev.new +##' @export +print.arrangelist = function(x, ...) lapply(x, function(.x) { + if(dev.interactive()) dev.new() else grid.newpage() + grid.draw(.x) +}, ...) diff -Nru r-cran-gridextra-0.9-1/R/arrange.r r-cran-gridextra-2.0.0/R/arrange.r --- r-cran-gridextra-0.9-1/R/arrange.r 2012-08-09 00:47:36.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/arrange.r 1970-01-01 00:00:00.000000000 +0000 @@ -1,247 +0,0 @@ -##' arrange ggplot2, lattice, and grobs on a page -##' -##' @aliases grid.arrange arrangeGrob latticeGrob drawDetails.lattice print.arrange -##' @title arrangeGrob -##' @param ... plots of class ggplot2, trellis, or grobs, and valid arguments to grid.layout -##' @param main string, or grob (requires a well-defined height, see example) -##' @param sub string, or grob (requires a well-defined height, see example) -##' @param legend string, or grob (requires a well-defined width, see example) -##' @param left string, or grob (requires a well-defined width, see example) -##' @param as.table logical: bottom-left to top-right or top-left to bottom-right -##' @param clip logical: clip every object to its viewport -##' @return return a frame grob; side-effect (plotting) if plot=T -##' @export -##' -##' @examples -##' \dontrun{ -##' require(ggplot2) -##' plots = lapply(1:5, function(.x) qplot(1:10,rnorm(10), main=paste("plot",.x))) -##' require(gridExtra) -##' do.call(grid.arrange, plots) -##' require(lattice) -##' grid.arrange(qplot(1:10), xyplot(1:10~1:10), -##' tableGrob(head(iris)), nrow=2, as.table=TRUE, main="test main", -##' sub=textGrob("test sub", gp=gpar(font=2))) -##' } -arrangeGrob <- function(..., as.table=FALSE, clip=TRUE, - main=NULL, sub=NULL, left=NULL, - legend=NULL) { - - - if(is.null(main)) main <- nullGrob() - if(is.null(sub)) sub <- nullGrob() - if(is.null(legend)) legend <- nullGrob() - if(is.null(left)) left <- nullGrob() - - if(is.character(main)) main <- textGrob(main) - if(is.character(sub)) sub <- textGrob(sub) - if(is.character(legend)) legend <- textGrob(legend, rot=-90) - if(is.character(left)) left <- textGrob(left, rot=90) - - arrange.class <- "arrange" # grob class - - dots <- list(...) - - params <- c("nrow", "ncol", "widths", "heights", - "default.units", "respect", "just" ) - ## names(formals(grid.layout)) - layout.call <- intersect(names(dots), params) - params.layout <- dots[layout.call] - if(is.null(names(dots))) - not.grobnames <- FALSE else - not.grobnames <- names(dots) %in% layout.call - - grobs <- dots[! not.grobnames ] - - n <- length(grobs) - - nm <- n2mfrow(n) - - if(is.null(params.layout$nrow) & is.null(params.layout$ncol)) - { - params.layout$nrow = nm[1] - params.layout$ncol = nm[2] - } - if(is.null(params.layout$nrow)) - params.layout$nrow = ceiling(n/params.layout$ncol) - if(is.null(params.layout$ncol)) - params.layout$ncol = ceiling(n/params.layout$nrow) - - nrow <- params.layout$nrow - ncol <- params.layout$ncol - - lay <- do.call(grid.layout, params.layout) - - fg <- frameGrob(layout=lay) - - ## if a ggplot is present, make the grob derive from the ggplot class - classes <- lapply(grobs, class) - inherit.ggplot <- any("ggplot" %in% unlist(classes)) - if(inherit.ggplot) arrange.class <- c(arrange.class, "ggplot") - - ii.p <- 1 - for(ii.row in seq(1, nrow)){ - ii.table.row <- ii.row - if(as.table) {ii.table.row <- nrow - ii.table.row + 1} - for(ii.col in seq(1, ncol)){ - ii.table <- ii.p - if(ii.p > n) break - - ## select current grob - cl <- class(grobs[[ii.table]]) - ct <- if("grob" %in% unlist(cl)) "grob" else - if("ggplot" %in% unlist(cl)) "ggplot" else cl - - g.tmp <- switch(ct, - ggplot = ggplotGrob(grobs[[ii.table]]), - trellis = latticeGrob(grobs[[ii.table]]), - grob = grobs[[ii.table]], - stop("input must be grobs!")) - - if(clip) # gTree seems like overkill here ? - g.tmp <- gTree(children=gList(clipGrob(), g.tmp)) - - fg <- placeGrob(fg, g.tmp, row=ii.table.row, col=ii.col) - ii.p <- ii.p + 1 - } - } - - ## optional annotations in a frame grob - wl <- unit(1, "grobwidth", left) - wr <- unit(1, "grobwidth", legend) - hb <- unit(1, "grobheight", sub) - ht <- unit(1, "grobheight", main) - - annotate.lay <- grid.layout(3, 3, - widths=unit.c(wl, unit(1, "npc")-wl-wr, wr), - heights=unit.c(ht, unit(1, "npc")-hb-ht, hb)) - - af <- frameGrob(layout=annotate.lay) - - af <- placeGrob(af, fg, row=2, col=2) - af <- placeGrob(af, main, row=1, col=2) - af <- placeGrob(af, sub, row=3, col=2) - af <- placeGrob(af, left, row=2, col=1) - af <- placeGrob(af, legend, row=2, col=3) - - - invisible(gTree(children=gList(af), cl=arrange.class)) -} - -##' @export -grid.arrange <- function(..., as.table=FALSE, clip=TRUE, - main=NULL, sub=NULL, left=NULL, legend=NULL, - newpage=TRUE){ - if(newpage) grid.newpage() - grid.draw(arrangeGrob(...,as.table=as.table, clip=clip, - main=main, sub=sub, left=left, legend=legend)) -} - -##' @export -latticeGrob <- function(p, ...){ - grob(p=p, ..., cl="lattice") -} - -##' @export -drawDetails.lattice <- function(x, recording=FALSE){ - lattice:::plot.trellis(x$p, newpage=FALSE) -} - -##' @export -print.arrange <- function(x, newpage = is.null(vp), vp = NULL, ...) { - if(newpage) grid.newpage() - grid.draw(editGrob(x, vp=vp)) -} - -##' Interface to arrangeGrob that can dispatch on multiple pages -##' -##' If the layout specifies both nrow and ncol, the list of grobs can be split -##' in multiple pages. Interactive devices print open new windows, whilst non-interactive -##' devices such as pdf call grid.newpage() between the drawings. -##' @title marrangeGrob -##' @aliases marrangeGrob print.arrangelist -##' @param ... grobs -##' @param as.table see \link{arrangeGrob} -##' @param clip see \link{arrangeGrob} -##' @param top see \link{arrangeGrob} -##' @param bottom see \link{arrangeGrob} -##' @param left see \link{arrangeGrob} -##' @param right see \link{arrangeGrob} -##' @return a list of class arrangelist -##' @author baptiste Auguie -##' @export -##' @family user -##' @examples -##' \dontrun{ -##' require(ggplot2) -##' pl <- lapply(1:11, function(.x) qplot(1:10,rnorm(10), main=paste("plot",.x))) -##' ml <- do.call(marrangeGrob, c(pl, list(nrow=2, ncol=2))) -##' ## interactive use; open new devices -##' ml -##' ## non-interactive use, multipage pdf -##' ggsave("multipage.pdf", ml) -##' } -marrangeGrob <- function(..., as.table=FALSE, clip=TRUE, - top=quote(paste("page", g, "of", pages)), - bottom=NULL, left=NULL, right=NULL){ - - arrange.class <- "arrange" # grob class - - dots <- list(...) - - params <- c("nrow", "ncol", "widths", "heights", - "default.units", "respect", "just" ) - ## names(formals(grid.layout)) - layout.call <- intersect(names(dots), params) - params.layout <- dots[layout.call] - if(is.null(names(dots))) - not.grobnames <- FALSE else - not.grobnames <- names(dots) %in% layout.call - - grobs <- dots[! not.grobnames ] - - n <- length(grobs) - - nm <- n2mfrow(n) - - if(is.null(params.layout$nrow) & is.null(params.layout$ncol)) - { - params.layout$nrow = nm[1] - params.layout$ncol = nm[2] - } - if(is.null(params.layout$nrow)) - params.layout$nrow = ceiling(n/params.layout$ncol) - if(is.null(params.layout$ncol)) - params.layout$ncol = ceiling(n/params.layout$nrow) - - nrow <- params.layout$nrow - ncol <- params.layout$ncol - - ## if nrow and ncol were given, may need multiple pages - nlay <- with(params.layout, nrow*ncol) - - ## add one page if division is not complete - pages <- n %/% nlay + as.logical(n %% nlay) - - groups <- split(seq_along(grobs), - gl(pages, nlay, n)) - - pl <- - lapply(names(groups), function(g) - { - top <- eval(top) ## lazy evaluation - do.call(arrangeGrob, c(grobs[groups[[g]]], params.layout, - list(as.table=as.table, clip=clip, - main=top, sub=bottom, left=left, legend=right))) - }) - - class(pl) <- c("arrangelist", "ggplot", class(pl)) - pl - -} - -##' @export -print.arrangelist = function(x, ...) lapply(x, function(.x) { - if(dev.interactive()) dev.new() else grid.newpage() - grid.draw(.x) -}, ...) diff -Nru r-cran-gridextra-0.9-1/R/barbedGrob.r r-cran-gridextra-2.0.0/R/barbedGrob.r --- r-cran-gridextra-0.9-1/R/barbedGrob.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/barbedGrob.r 1970-01-01 00:00:00.000000000 +0000 @@ -1,125 +0,0 @@ -##' plot lines and symbols -##' -##' @aliases barbedGrob grid.barbed -##' @title barbedGrob -##' @param x coordinates -##' @param y coordinates -##' @param size unit vector for the symbols -##' @param pch vector of symbol types -##' @param space numeric scaling factor for the exclusion zone -##' @param only.lines logical: should only split lines be returned? -##' @param arrow arrow passed to grid.segments -##' @param gp gpar() object for the symbols -##' @param name grob name -##' @param default.units default units -##' @param vp viewport -##' @return a grob -##' @export -##' @seealso \code{grid.segments}, \code{grid.points} -##' -##' @family grob userlevel -##' @examples -##' set.seed(1234) -##' grid.barbed(name="test") -##' grid.edit("test", gp=gpar(fill="blue", lwd=3)) -##' grid.edit("test::points", pch=22) -##' grid.newpage() -##' g <- -##' barbedGrob(size=unit(1:5, "char"), only=FALSE, -##' gp=gpar(col="red", lex=3, fill="blue", alpha=0.5, pch=3)) -##' -##' pushViewport(vp=viewport(width=1, height=1)) -##' grid.rect(gp=gpar(fill="thistle2")) -##' grid.grill(gp=gpar(col="lavenderblush1", lwd=3, lty=3)) -##' grid.draw(g) -##' x <- c(0.2, 0.7) -##' y <- x -##' dev.new(width=3, height=7) -##' grid.newpage() -##' g <- -##' barbedGrob(x, y, size=unit(c(2, 10), "mm")) -##' pushViewport(vp=viewport(width=1, height=1)) -##' grid.draw(g) -##' grid.points(x, y, pch=3) - -barbedGrob <- function(x = stats::runif(10), y = stats::runif(10), - size = unit(sample(1:4, 10, replace=TRUE), "char"), - pch = 21, arrow=NULL, - space=1, only.lines=FALSE, - gp = gpar(), - name=NULL, default.units = "npc", vp = NULL){ - - - n <- length(x) - - if(n > 1){ # there is more than one point: we can draw segments - if(length(size) < n) size <- rep(size, length=n) - - dx <- diff(x) - dy <- diff(y) - - ## duplicate the points to make split segments - new.x <- rep(x, each=2)[-c(1, 2*length(x))] - new.y <- rep(y, each=2)[-c(1, 2*length(y))] - sizex <- convertUnit(size, default.units, 'x', "dimension", valueOnly=TRUE) - sizey <- convertUnit(size, default.units, 'y', "dimension", valueOnly=TRUE) - - new.sizex <- rep(sizex, each=2, length=2*n)[-c(1, 2*n)] - new.sizey <- rep(sizey, each=2, length=2*n)[-c(1, 2*n)] - - ## strip units before rep (bug in [.unit) - - length <- sqrt(dx^2 + dy^2) # length of initial segments - exclusionx <- 0.5 * rep(space, length(new.sizex)) * new.sizex - exclusiony <- 0.5 * rep(space, length(new.sizey)) * new.sizey - - length.exc <- sqrt(exclusionx^2 + exclusiony^2) - - scaling <- length.exc / rep(length, each=2) # exclusion factor around each point - - start <- seq(1, by=2, length(new.x)) # starting points - end <- seq(2, by=2, length(new.x)) # end points - - x.start <- scaling[start] * dx[(start+1)/2] + new.x[start] # shift the points - y.start <- scaling[start] * dy[(start+1)/2] + new.y[start] # keeping the direction of the initial segments - - x.end <- new.x[end] - scaling[end] * dx[end/2] - y.end <- new.y[end] - scaling[end] * dy[end/2] - - - grob.lines <- segmentsGrob(x0 = x.start, y0 = y.start, - x1 = x.end, y1=y.end, arrow=arrow, - default.units=default.units, - gp = gpar(lineend = "butt"), name = "lines") - -} else { - grob.lines <- NULL -} - -if(!only.lines){ - grob.points <- pointsGrob(x, y, size=size, - default.units=default.units, pch=pch, - gp = gpar(lty=1, linejoin = "mitre"), - name = "points") -}else{ # no points - grob.points <- NULL -} - - children <- gList(grob.lines, grob.points) - -gTree(x = x, y = y, size = size, - pch = pch, - space=space, only.lines=only.lines, - name=name, default.units = default.units, - vp = vp, gp=gp, children = children, - cl = 'barbed') - -} - -##' @export -grid.barbed <- function(...){ - g = barbedGrob(...) - grid.draw(g) - invisible(g) -} - diff -Nru r-cran-gridextra-0.9-1/R/borderGrob.r r-cran-gridextra-2.0.0/R/borderGrob.r --- r-cran-gridextra-0.9-1/R/borderGrob.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/borderGrob.r 1970-01-01 00:00:00.000000000 +0000 @@ -1,47 +0,0 @@ -##' an open rectangular borderdraw -##' -##' @aliases borderGrob grid.border -##' @title borderGrob -##' @param type which borders to draw -##' @param colour colour -##' @param ... additional arguments passed to gpar() -##' @param vp viewport -##' @return a grob -##' @seealso \code{grid.segments}, \code{grid.points} -##' @family grob userlevel -##' @export -##' -##' @examples -##' pushViewport(viewport(width=0.5, height=0.5, layout=grid.layout(4, 4, w=0.9, height=0.9))) -##' vp = viewport(width=0.9, height=0.9) -##' type <- 1 -##' for(ii in 1:4){ -##' for(jj in 1:4){ -##' pushViewport(viewport(layout.pos.r=ii, layout.pos.c=jj)) -##' grid.rect(gp=gpar(col="grey",fill="black")) -##' grid.text(paste("t = ", type), gp=gpar(col="white")) -##' grid.border(type, vp=vp) -##' upViewport() -##' type <- type + 1 -##' } -##' } - - -borderGrob <- function(type=1, colour="white", vp=NULL, ...){ - - xs <- c(0, 1, 1, 0) - xe <- c(1, 1, 0, 0) - ys <- c(0, 0, 1, 1) - ye <- c(0, 1, 1, 0) - - cols <- as.matrix(do.call(expand.grid, rep(list(c(NA,colour)), 4)))[c(1,2,3,5,9,4,7,13,10,6,11,8,15,14,12,16), ] - -segmentsGrob(xs, ys, xe, ye, gp=gpar(col=cols[type, ], ...), vp=vp) - -} - -##' @export -grid.border <- function(...){ - grid.draw(borderGrob(...)) -} - diff -Nru r-cran-gridextra-0.9-1/R/colorstripGrob.r r-cran-gridextra-2.0.0/R/colorstripGrob.r --- r-cran-gridextra-0.9-1/R/colorstripGrob.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/colorstripGrob.r 1970-01-01 00:00:00.000000000 +0000 @@ -1,66 +0,0 @@ -##' strip of colors -##' -##' @aliases colorstripGrob grid.colorstrip -##' @title colorstrip -##' @param fill vector of colours -##' @param colour vector of colours -##' @param draw logical -##' @param direction direction (horizontal or vertical) -##' @param raster logical, use grid.raster (with interpolation) -##' @return a grob -##' @seealso \code{grid.rect} -##' @family grob userlevel -##' @export -##' -##' @examples -##' colorstripGrob(c("#E41A1C", "#377EB8", "#4DAF4A")) - -colorstripGrob <- - function (fill = 1:3, colour = fill, draw = TRUE, raster = FALSE, - direction = c("vertical", "horizontal")) -{ - - fill.numeric <- is.numeric(fill) - fill[fill.numeric] <- rgb(t(col2rgb(fill[fill.numeric])), maxColorValue=255) - - direction <- match.arg(direction) - - my.grob <- if (raster) { - - fillm <- switch(direction, - "horizontal" = matrix(fill, nrow = 1), - "vertical" = matrix(fill, ncol = 1)) - - rasterGrob(fillm, x = unit(0.5, "npc"), - y = unit(0.5, "npc"), width = unit(1, "npc"), - height = unit(1, "npc"), just = "centre", - hjust = NULL, vjust = NULL, - interpolate = TRUE, default.units = "npc", name = NULL, - gp = gpar(), vp = NULL) - } else { - positions <- cbind(seq(0 + 0.5/length(fill), - 1 - 0.5/length(fill), length = length(fill)), - rep(0.5, length(fill)), - 1/length(fill), 1) - - xy <- switch(direction, - "horizontal" = positions[, 1:4, drop=FALSE], - "vertical" = positions[seq(nrow(positions), 1), c(2:1, 4:3), drop=FALSE]) - - grid.rect(x = unit(xy[, 1], "npc"), y = unit(xy[, 2], "npc"), - width = unit(xy[, 3], "npc"), - height = unit(xy[, 4], "npc"), just = "center", - hjust = NULL, vjust = NULL, default.units = "npc", - name = NULL, gp = gpar(fill = fill, col = colour), - draw = FALSE, vp = NULL) - } - if (draw) - grid.draw(my.grob) - - my.grob -} - -##' @export -grid.colorstrip <- function(...) - grid.draw(colorstripGrob(...)) - diff -Nru r-cran-gridextra-0.9-1/R/ebimage.r r-cran-gridextra-2.0.0/R/ebimage.r --- r-cran-gridextra-0.9-1/R/ebimage.r 2012-08-09 00:54:28.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/ebimage.r 1970-01-01 00:00:00.000000000 +0000 @@ -1,55 +0,0 @@ -##' create a grob from EBImage object -##' -##' @param pic object of class Image -##' @param x x unit -##' @param y y unit -##' @param scale numeric scale factor -##' @param raster logical: use rasterGrob(R>=2.11) or imageGrob(RGraphics) -##' @param angle numeric: angle in degrees -##' @param ... optional grob parameters, passed to imageGrob or rasterGrob -##' @details Very primitive function, using RGraphics' imageGrob or rasterGrob (R>2.11) -##' @return a gTree of class 'ebimage', with natural width and height in points -##' @family grob userlevel -##' @export -##' -##' @examples -##' \dontrun{ -##' library(EBImage) -##' library(RGraphics) -##' x <- readImage("http://www.google.com/logos/teachersday09.gif") -##' g1 <- ebimageGrob(x) -##' dev.new(width=g1$width/72, height=g1$height/72) -##' grid.draw(g1) -##' } - -ebimageGrob <- -function (pic, x=0.5, y=0.5, scale=1, raster=FALSE, angle = NULL, ...) -{ - dims <- dim(pic) - colours = t(channel(pic, "x11")) - width = unit(scale*dims[1], "points") - height = unit(scale*dims[2], "points") - angle <- if(is.null(angle)) 0 else angle - vp <- viewport(x=x, y=y, width=width, height=height, angle=angle) - - if(raster){ - - child <- - rasterGrob(colours, vp=vp, ...) - - } else { - colours <- colours[ rev(seq_len(nrow(colours))), ] - require(RGraphics) - child <- - imageGrob(dims[2], dims[1], cols=colours, gp=gpar(col=colours), byrow=FALSE, vp=vp, ...) - } - - gTree(width= width[[1]], - height = height[[1]], - children=gList(child), cl="ebimage") - -} - -if (getRversion() >= "2.15.1") - utils::globalVariables(c("channel")) - diff -Nru r-cran-gridextra-0.9-1/R/ellipseGrob.r r-cran-gridextra-2.0.0/R/ellipseGrob.r --- r-cran-gridextra-0.9-1/R/ellipseGrob.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/ellipseGrob.r 1970-01-01 00:00:00.000000000 +0000 @@ -1,68 +0,0 @@ -##' an ellipse grob -##' -##' @aliases ellipseGrob grid.ellipse -##' @title ellipseGrob -##' @param x x unit -##' @param y y unit -##' @param size size -##' @param angle angle -##' @param ar aspec ratio -##' @param gp gpar -##' @param default.units default units -##' @param size.units size units -##' @return grob -##' @export -##' @family grob userlevel -##' -##' @examples -##' g = ellipseGrob(1:10/11,1:10/11,size=5,ar=1:5,angle=rnorm(10), -##' def="npc", gp=gpar(fill=grey(1:10/11))) -##' grid.draw(g) - -ellipseGrob <- function(x, y, size = 1, angle=rep(pi/2, length(x)), - ar =1, - gp=gpar(colour = "grey50", fill = "grey90"), - default.units="native", size.units="mm") { - - stopifnot(length(y) == length(x)) - - n <- length(x) - size <- size / 2 # polygon.regular has radius unity - - if(length(size) < n ) size <- rep(size, length.out=n) - if(length(ar) < n ) ar <- rep(ar, length.out=n) - if(length(angle) < n ) angle <- rep(angle, length.out=n) - - ngonC <- polygon.regular(50) # seems enough for a smooth curve - ngonC <- lapply(seq_along(x), function(ii) ngonC) - -## stretch the polygons, then rotate them -## aspect ratio factor for constant area - ngonC.list <- - lapply(seq_along(ngonC), function(ii) - size[ii] * ngonC[[ii]] %*% - matrix(c(sqrt(ar[ii]), 0, 0, 1/sqrt(ar[ii])), ncol=2) %*% - matrix(c(cos(angle[ii]), -sin(angle[ii]), - sin(angle[ii]), cos(angle[ii])), nrow = 2) - ) - - vertices <- sapply(ngonC.list, nrow) - reps.x <- do.call(c, lapply(seq_along(x), function(ii) rep(x[ii], vertices[ii]))) - reps.y <- do.call(c, lapply(seq_along(y), function(ii) rep(y[ii], vertices[ii]))) - - ngonXY <- do.call(rbind, ngonC.list) - - polygonGrob( - x = unit(ngonXY[, 1], size.units) + unit(reps.x, default.units), - y = unit(ngonXY[, 2], size.units) + unit(reps.y, default.units), - default.units = default.units, - id.lengths = unlist(vertices), gp = gp) -} - - - -##' @export -grid.ellipse <- function(...) - { - grid.draw(ellipseGrob(...)) - } diff -Nru r-cran-gridextra-0.9-1/R/gridExtra-package.r r-cran-gridextra-2.0.0/R/gridExtra-package.r --- r-cran-gridextra-0.9-1/R/gridExtra-package.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/gridExtra-package.r 2015-07-14 08:01:00.000000000 +0000 @@ -1,15 +1,15 @@ -##' functions for Grid graphics -##' -##' @name gridExtra-package -##' @aliases gridExtra -##' @docType package -##' @import grid -##' @title misc. high-level functions for Grid graphics -##' @author baptiste Auguie \email{baptiste.auguie@@gmail.com} -##' @references -##' R Graphics by Paul Murrell, ggplot2 source code -##' @keywords packagelibrary -##' @seealso \code{\link{Grid}} -##' +#' @title Miscellaneous Functions for "Grid" Graphics +#' @description Provides a number of user-level functions to work with "grid" graphics, notably to arrange multiple grid-based plots on a page, and draw tables. +#' @name gridExtra-package +#' @aliases gridExtra +#' @docType package +#' @author baptiste Auguie \email{baptiste.auguie@@gmail.com} +#' @import gtable +#' @import grid +#' @references +#' R Graphics by Paul Murrell (Chapman & Hall/CRC, August 2005) +#' @keywords packagelibrary +#' @seealso \code{\link{Grid}} +#' function() NULL diff -Nru r-cran-gridextra-0.9-1/R/grob-utils.r r-cran-gridextra-2.0.0/R/grob-utils.r --- r-cran-gridextra-0.9-1/R/grob-utils.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/grob-utils.r 2015-07-11 01:46:54.000000000 +0000 @@ -1,76 +1,128 @@ -##' zero grob borrowed from ggplot2 -##' -##' @aliases virtualGrob grobHeight.virtual grobWidth.virtual drawDetails.virtual is.zero widthDetails.virtual heightDetails.virtual -##' @title virtualGrob -##' @export -##' @family grob userlevel - -virtualGrob <- grob(cl = "virtual", name = "NULL") -##' @export -widthDetails.virtual <-function(x) unit(0, "cm") -##' @export -heightDetails.virtual <- function(x) unit(0, "cm") -##' @export -grobWidth.virtual <- function(x) unit(0, "cm") -##' @export -grobHeight.virtual <- function(x) unit(0, "cm") -##' @export -drawDetails.virtual <- function(x, recording) {} - -##' mix two vectors -##' -##' @aliases interleaven -##' @title interleaven -##' @param x vector -##' @param y vector -##' @param n integer -##' @return a vector -##' @seealso \code{rep}, \code{ggplot2:interleave} -##' @family grob userlevel -##' @export -##' -##' @examples -##' interleaven(replicate(3, rectGrob(), simplify=FALSE), replicate(12, virtualGrob, simplify=FALSE), 4) - -interleaven <- function(x = letters[1:3], y=1:12, n=4){ -ord <- as.vector(rbind(seq_along(x), matrix(length(x)+seq_along(y), nrow=n, byrow=FALSE))) -c(x, y)[ord] - } - -##' calculates the max of a list of units arranged in a matrix -##' -##' @aliases rowMax.units colMax.units -##' @title rowMax.units -##' @param u list of units -##' @param nrow nrow -##' @return a vector of units -##' @export -##' @seealso \code{unit.c}, \code{unit} - -rowMax.units <- function(u, nrow){ # rowMax with a fake matrix of units - matrix.indices <- matrix(seq_along(u), nrow=nrow) - do.call(unit.c, lapply(seq(1, nrow), function(ii) { - max(u[matrix.indices[ii, ]]) - })) -} - -##' @export -colMax.units <- function(u, ncol){ # colMax with a fake matrix of units - matrix.indices <- matrix(seq_along(u), ncol=ncol) - do.call(unit.c, lapply(seq(1, ncol), function(ii) { - max(u[matrix.indices[, ii]]) - })) -} - - -##' expand a list of arguments to full length (and misc. undocumented functions) -##' -##' @title expand.arguments -##' @aliases expand.arguments updatelist textii rectii pchlist -##' @param ... arguments -##' @return ... -expand.arguments <- function(...){ - dotList <- list(...) - max.length <- max(sapply(dotList, length)) - lapply(dotList, rep, length=max.length) +latticeGrob <- function(p, ...){ + grob(p=p, ..., cl="lattice") +} + + +#' @importFrom graphics plot +#' @export +drawDetails.lattice <- function(x, recording=FALSE){ + stopifnot(requireNamespace("lattice", quietly = TRUE)) + plot(x$p, newpage=FALSE) +} + + +row_heights <- function(m){ + do.call(unit.c, apply(m, 1, function(l) + max(do.call(unit.c, lapply(l, grobHeight))))) +} + +col_widths <- function(m){ + do.call(unit.c, apply(m, 2, function(l) + max(do.call(unit.c, lapply(l, grobWidth))))) +} + + +insert.unit <- function (x, values, after = length(x)) { + lengx <- length(x) + if (lengx == 0) return(values) + if (length(values) == 0) return(x) + + if (after <= 0) { + unit.c(values, x) + } else if (after >= lengx) { + unit.c(x, values) + } else { + unit.c(x[1L:after], values, x[(after + 1L):lengx]) + } +} + +z_normalise <- function (x, i = 1) +{ + x$layout$z <- rank(x$layout$z, ties.method = "first") + i - + 1 + x +} + +z_arrange_gtables <- function (gtables, z) +{ + if (length(gtables) != length(z)) { + stop("'gtables' and 'z' must be the same length") + } + zmax <- 0 + for (i in order(z)) { + if (nrow(gtables[[i]]$layout) > 0) { + gtables[[i]] <- z_normalise(gtables[[i]], zmax + + 1) + zmax <- max(gtables[[i]]$layout$z) + } + } + gtables +} + +rbind.gtable <- function(..., size = "max", z = NULL) { + gtables <- list(...) + if (!is.null(z)) { + gtables <- z_arrange_gtables(gtables, z) + } + Reduce(function(x, y) rbind_gtable(x, y, size = size), gtables) +} + +rbind_gtable <- function(x, y, size = "max") { + stopifnot(ncol(x) == ncol(y)) + if (nrow(x) == 0) return(y) + if (nrow(y) == 0) return(x) + + y$layout$t <- y$layout$t + nrow(x) + y$layout$b <- y$layout$b + nrow(x) + x$layout <- rbind(x$layout, y$layout) + + x$heights <- insert.unit(x$heights, y$heights) + x$rownames <- c(x$rownames, y$rownames) + + size <- match.arg(size, c("first", "last", + "max", "min")) + x$widths <- switch(size, + first = x$widths, + last = y$widths, + min = unit.pmin(x$widths, y$widths), + max = unit.pmax(x$widths, y$widths) + ) + + x$grobs <- append(x$grobs, y$grobs) + + x +} + +cbind.gtable <- function(..., size = "max", z = NULL) { + gtables <- list(...) + if (!is.null(z)) { + gtables <- z_arrange_gtables(gtables, z) + } + Reduce(function(x, y) cbind_gtable(x, y, size = size), gtables) +} + +cbind_gtable <- function(x, y, size = "max") { + stopifnot(nrow(x) == nrow(y)) + if (ncol(x) == 0) return(y) + if (ncol(y) == 0) return(x) + + y$layout$l <- y$layout$l + ncol(x) + y$layout$r <- y$layout$r + ncol(x) + x$layout <- rbind(x$layout, y$layout) + + x$widths <- insert.unit(x$widths, y$widths) + x$colnames <- c(x$colnames, y$colnames) + + size <- match.arg(size, c("first", "last", + "max", "min")) + + x$heights <- switch(size, + first = x$heights, + last = y$heights, + min = unit.pmin(x$heights, y$heights), + max = unit.pmax(x$heights, y$heights)) + + x$grobs <- append(x$grobs, y$grobs) + + x } diff -Nru r-cran-gridextra-0.9-1/R/ngonGrob.r r-cran-gridextra-2.0.0/R/ngonGrob.r --- r-cran-gridextra-0.9-1/R/ngonGrob.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/ngonGrob.r 2015-07-13 22:40:19.000000000 +0000 @@ -1,66 +1,147 @@ -##' regular polygon grob -##' -##' @aliases ngonGrob grid.ngon -##' @title ngonGrob +##' @aliases ngonGrob grid.ngon ellipseGrob grid.ellipse +##' @title Regular polygon grob +##' @description Regular polygons with optional rotation, stretching, and aesthetic attributes +##' @describeIn ngonGrob return a polygon grob ##' @param x x unit ##' @param y y unit -##' @param sides sides -##' @param size size -##' @param angle angle -##' @param ar ar -##' @param units.def units.def -##' @param units.size units.size +##' @param n number of vertices +##' @param size radius of circumscribing circle +##' @param phase angle in radians of first point relative to x axis +##' @param rho aspect ratio +##' @param angle angle of polygon in radians +##' @param position.units default units for the positions +##' @param size.units grid units for the sizes ##' @param gp gpar +##' @param ... further parameters passed to polygonGrob ##' @return grob -##' @include polygon.regular.r ##' @export -##' @family grob userlevel -##' ##' @examples -#' pushViewport(dataViewport(0:1, 0:1, width=unit(2, "cm"), height=unit(2, "cm"))) -#' -#' xy <- polygon.regular(6, TRUE) -#' grid.ngon(0.5, 0.5, 6, 10, units.size="mm") -#' for(ii in 1:NROW(xy)){ -#' grid.ngon(xy[ii, 1]+0.5, xy[ii, 2]+0.5, 6, 10, units.size="mm") -#' } -#' upViewport() - - -ngonGrob <- function (x, y, sides = 5, size = 1, - angle = rep(pi/2, length(x)), - ar = rep(1, length(x)), - gp = gpar(colour = "grey50", fill = "grey90", - linejoin = "mitre"), - units.def = "native", units.size="mm") +##' library(grid) +##' N <- 5 +##' xy <- polygon_regular(N)*2 +##' +##' # draw multiple polygons +##' g <- ngonGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), +##' unit(xy[,2],"cm") + unit(0.5,"npc"), +##' n = seq_len(N) + 2, gp=gpar(fill=1:N)) +##' +##' grid.newpage() +##' grid.draw(g) +##' +##' # rotated and stretched +##' g2 <- ngonGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), +##' unit(xy[,2],"cm") + unit(0.5,"npc"), +##' n = seq_len(N) + 2, rho = seq_len(N), +##' phase = 0, angle=pi/(seq_len(N)+2), +##' size=1:N+5) +##' +##' grid.newpage() +##' grid.draw(g2) +##' +##' # ellipse +##' g3 <- ellipseGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), +##' unit(xy[,2],"cm") + unit(0.5,"npc"), +##' angle=-2*seq(0,N-1)*pi/5+pi/2, +##' size=5, rho=1/3) +##' +##' grid.newpage() +##' grid.draw(g3) +ngonGrob <- function (x, y, n = 5, size = 5, phase = pi/2, + angle = 0, rho = 1, + gp = gpar(colour = "black", fill = NA, + linejoin = "mitre"), ..., + position.units = "npc", size.units="mm") { - stopifnot(length(y) == length(x)) - n <- length(x) - if (length(size) < n) - size <- rep(size, length.out = n) - if (length(sides) < n) - sides <- rep(sides, length.out = n) - ngonC <- lapply(sides, polygon.regular) - ngonC.list <- lapply(seq_along(ngonC), function(ii) size[ii] * - ngonC[[ii]] %*% - matrix(c(sqrt(ar[ii]), 0, 0, 1/sqrt(ar[ii])), ncol = 2) %*% - matrix(c(cos(angle[ii]), -sin(angle[ii]), - sin(angle[ii]), cos(angle[ii])), nrow = 2)) - vertices <- sapply(ngonC.list, nrow) - reps.x <- do.call(c, lapply(seq_along(x), - function(ii) rep(x[ii], vertices[ii]))) - reps.y <- do.call(c, lapply(seq_along(y), - function(ii) rep(y[ii], vertices[ii]))) - ngonXY <- do.call(rbind, ngonC.list) - - polygonGrob(x = unit(ngonXY[, 1], units.size) + unit(reps.x, units.def), - y = unit(ngonXY[, 2], units.size) + unit(reps.y, units.def), - default.units = units.def, id.lengths = unlist(vertices), - gp = gp) + N <- length(x) + stopifnot(length(y) == N) + + if (!is.unit(x)) + x <- unit(x, position.units) + if (!is.unit(y)) + y <- unit(y, position.units) + + xv <- convertX(x, position.units, TRUE) + yv <- convertY(y, position.units, TRUE) + + if (length(n) < N) + n <- rep(n, length.out = N) + if (length(size) < N) + size <- rep(size, length.out = N) + if (length(phase) < N) + phase <- rep(phase, length.out = N) + if (length(angle) < N) + angle <- rep(angle, length.out = N) + if (length(rho) < N) + rho <- rep(rho, length.out = N) + + lngon <- mapply(polygon_regular, n = n, phase = phase, + SIMPLIFY = FALSE) + vertices <- sapply(lngon, nrow) + + # browser() + stretch_rotate_move <- function(p, size, rho, angle, x, y){ + central <- size * p %*% + diag(c(1/sqrt(rho), sqrt(rho))) %*% + rbind(c(cos(angle), -sin(angle)), + c(sin(angle), cos(angle))) + + list(x = unit(central[,1], size.units) + unit(x, position.units), + y = unit(central[,2], size.units) + unit(y, position.units)) + + } + + lxy <- mapply(stretch_rotate_move, p=lngon, + size=size, rho=rho, angle=angle, + x=xv, y=yv, + SIMPLIFY = FALSE) + + allx <- do.call("unit.c", lapply(lxy, "[[", 1)) + ally <- do.call("unit.c", lapply(lxy, "[[", 2)) + + polygonGrob(allx, ally, id.lengths = vertices, gp = gp, ...) + } -##' @export + +#' @describeIn ngonGrob draw a polygon grob on the current device +#' @inheritParams ngonGrob +#' @export grid.ngon <- function(...) - { - grid.draw(ngonGrob(...)) - } +{ + grid.draw(ngonGrob(...)) +} + + +#' @describeIn ngonGrob return an ellipse grob +#' @inheritParams ngonGrob +#' @export +ellipseGrob <- function(x, y, size = 5, + angle = pi/4, rho = 1, n = 50, + gp = gpar(colour = "black", fill = NA, + linejoin = "mitre"), ..., + position.units = "npc", size.units="mm") { + + ngonGrob(x, y, n = n , phase = 0, + size = size, angle = angle, rho = rho, + gp = gp, position.units = position.units, + size.units = size.units, ...) +} + + +#' @describeIn ngonGrob draw an ellipse grob +#' @inheritParams ngonGrob +#' @export +grid.ellipse <- function(...) +{ + grid.draw(ellipseGrob(...)) +} + + +#' @describeIn ngonGrob return the x,y coordinates of a regular polygon inscribed in the unit circle +#' @inheritParams ngonGrob +#' @export +polygon_regular <- function(n = 5, phase = 0){ + stopifnot(n > 2) + cc <- exp(seq(0, n)*2i*pi/n) * exp(1i*(phase+pi/2)) + cbind(Re(cc), Im(cc)) +} diff -Nru r-cran-gridextra-0.9-1/R/patternGrob.r r-cran-gridextra-2.0.0/R/patternGrob.r --- r-cran-gridextra-0.9-1/R/patternGrob.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/patternGrob.r 1970-01-01 00:00:00.000000000 +0000 @@ -1,185 +0,0 @@ -##' pattern grob -##' @aliases patternGrob grid.pattern widthDetails.pattern heightDetails.pattern drawDetails.pattern segments.pattern -##' @title patternGrob -##' @param x x unit -##' @param y y unit -##' @param width width -##' @param height height -##' @param pattern integer -##' @param orientation orientation -##' @param granularity unimplemented -##' @param motif.col motif.col -##' @param motif.fill motif.fill -##' @param motif.alpha motif.alpha -##' @param motif.cex motif.cex -##' @param pattern.offset pattern.offset -##' @param default.units default.units -##' @param clip clip -##' @param gp gp -##' @param ... additional params to the grob -##' @return grob of class pattern -##' @export -##' @family grob userlevel -##' -##' @examples -##' grid.pattern(x=seq(1/6, 5/6, length=6), width=unit(1/8,"npc"), height=unit(0.5,"npc"), -##' motif.width=unit(10, "mm"), pattern=c(1:6), orientation=45, motif.alpha=0.5, -##' motif.cex=c(1, 0.5), motif.col=1:2, motif.fill=NA, -##' gp=gpar(fill="blue", lwd=2, alpha=0.5), clip=TRUE) - -patternGrob <- function(x=unit(0.5, "npc"), y=unit(0.5, "npc"), - width=unit(1, "npc"), height=unit(1, "npc"), - pattern=2, - orientation=45, - granularity=unit(5, "mm"), - motif.col="black", - motif.fill= NULL, - motif.alpha=1, - motif.cex=1, - pattern.offset=c(0, 0), - default.units="npc", - clip=TRUE, - gp=gpar(fill=NA), ... - ){ - new <- expand.arguments(x=x, y=y, width=width, height=height, - motif.col=motif.col, motif.fill=motif.fill, - motif.alpha=motif.alpha, motif.cex=motif.cex, - pattern=pattern, orientation=orientation, granularity=granularity) - - with(new, - grob(x=x, y=y, width=width, height=height, - motif.col=motif.col, motif.fill=motif.fill, - motif.alpha=motif.alpha, motif.cex=motif.cex, - pattern=pattern, orientation=orientation, granularity=granularity, - pattern.offset=pattern.offset, clip=clip, - gp=gp,default.units=default.units, ..., cl="pattern")) - - } - -##' @export -widthDetails.pattern <- function(x) x$width -##' @export -heightDetails.pattern <- function(x) x$height - - -pchlist <- c(NA, 21, NA, 17, NA, 3) - - -segments.pattern <- function(width, height, - motif.size, - pattern.offset, angle){ - - max.length <- sqrt(width^2 + height^2) - n <- ceiling(max.length / motif.size) + 2 - - y0 <- y1 <- seq(-n/2*motif.size, n/2*motif.size, by=motif.size) - x0 <- -n/2*motif.size - x1 <- n/2*motif.size - - angler <- angle*pi/180 - - rotation <- - matrix(c(cos(angler), sin(angler), -sin(angler), cos(angler)), ncol=2, byrow=TRUE) - - coords <- cbind(cbind(x0, y0) %*% rotation, cbind(x1, y1) %*% rotation) - - params <- list(x0=unit(coords[, 1] + width/2 + pattern.offset[1], "mm"), - y0=unit(coords[, 2] + height/2 + pattern.offset[2], "mm"), - x1=unit(coords[, 3] + width/2 + pattern.offset[1], "mm"), - y1=unit(coords[, 4] + height/2 + pattern.offset[2], "mm"), - default.units="mm") - -} - - - -##' @export -drawDetails.pattern <- function(x, recording=TRUE){ - - ## calculate the number of tiles - - abs.size <- list(width=convertUnit(x$width, "mm", valueOnly=TRUE), - height=convertUnit(x$height, "mm", axisFrom = "y", valueOnly=TRUE), - motif.size=convertUnit(x$granularity, "mm", valueOnly=TRUE)) - - abs.size$pattern.offset <- with(abs.size, rep(x$pattern.offset*motif.size, 2)) - - nx <- with(abs.size, ceiling(width / motif.size) + 1) - ny <- with(abs.size, ceiling(height / motif.size) + 1) - - drawOne <- function(ii){ - - ## clip the pattern - pushViewport(viewport(x$x[ii], x$y[ii], - width=x$width[ii], height=x$height[ii], - clip=x$clip)) - - if(x$pattern[ii] == 1){ # draw solid lines - - do.call(grid.segments, - c(segments.pattern(abs.size$width[ii], abs.size$height[ii], - abs.size$motif.size[ii], - abs.size$pattern.offset, x$orientation[ii]), - list(gp=gpar(lty=1)))) - - } - if(x$pattern[ii] == 3){ # draw grid lines - - do.call(grid.segments, - c(segments.pattern(abs.size$width[ii], abs.size$height[ii], - abs.size$motif.size[ii], - abs.size$pattern.offset, x$orientation[ii]), - list(gp=gpar(lty=1, lex=x$motif.cex[ii])))) - - do.call(grid.segments, - c(segments.pattern(abs.size$width[ii], abs.size$height[ii], - abs.size$motif.size[ii], - abs.size$pattern.offset, -x$orientation[ii]), - list(gp=gpar(lty=1, lex=x$motif.cex[ii])))) - - } - if(x$pattern[ii] == 5){ # draw dashed lines - - do.call(grid.segments, - c(segments.pattern(abs.size$width[ii], abs.size$height[ii], - abs.size$motif.size[ii], - abs.size$pattern.offset, x$orientation[ii]), - list(gp=gpar(lty=2, lex=x$motif.cex[ii])))) - - } - - if(x$pattern[ii] %in% c(2, 4, 6)){ # draw points - - xy <- expand.grid(x=seq(-nx[ii]/2*abs.size$motif.size[ii], - nx[ii]/2*abs.size$motif.size[ii], by=abs.size$motif.size[ii]) , - y=seq(-ny[ii]/2*abs.size$motif.size[ii], - ny[ii]/2*abs.size$motif.size[ii], by=abs.size$motif.size[ii]) ) - - params <- c(list(x=unit(xy$x+abs.size$width[ii]/2 + - abs.size$pattern.offset[1], "mm")), - list(y=unit(xy$y+abs.size$height[ii]/2+ - abs.size$pattern.offset[2], "mm")), - list(gp=gpar(col=x$motif.col[ii], fill=x$motif.fill[ii], - alpha=x$motif.alpha[ii], cex=x$motif.cex[ii])), list(pch=pchlist[x$pattern[ii]]), - default.units="mm") - - do.call(grid.points, params) - } - - upViewport() - } - - grid.rect(x=x$x, y=x$y, - width=x$width, height=x$height, - just="center", gp=x$gp) - - ## overlay the pattern - be.quiet <- lapply(seq_along(x$x), drawOne) - -} - - -##' @export -grid.pattern <- function(...) - grid.draw(patternGrob(...)) - diff -Nru r-cran-gridextra-0.9-1/R/pixmap.r r-cran-gridextra-2.0.0/R/pixmap.r --- r-cran-gridextra-0.9-1/R/pixmap.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/pixmap.r 1970-01-01 00:00:00.000000000 +0000 @@ -1,102 +0,0 @@ -##' create a grob from pixmap object -##' -##' @param pic pixmap object -##' @param x x unit -##' @param y y unit -##' @param scale scale -##' @param raster raster -##' @param angle angle -##' @param vp viewport -##' @param ... optional grob parameters, passed to imageGrob or rasterGrob -##' @details Very primitive function, using RGraphics' imageGrob or rasterGrob (R>=2.11) -##' @return a gTree of class 'pixmap', with natural width and height in points -##' @family grob userlevel -##' @export -##' @examples -##' library(pixmap) -##' library(RGraphics) -##' x <- read.pnm(system.file("pictures/logo.ppm", package="pixmap")[1]) -##' g1 <- pixmapGrob(x) -##' dev.new(width=g1$width/72, height=g1$height/72) -##' grid.draw(g1) -pixmapGrob <- -function (pic, x=0.5, y=0.5, scale=1, raster=FALSE, angle=0, vp=NULL, ...) -{ - rast <- as.raster(pic) - pic = as(pic, "pixmapIndexed") - width = unit(scale*pic@bbox[3], "points") - height = unit(scale*pic@bbox[4], "points") - Z <- pic@index[nrow(pic@index):1, , - drop = FALSE] - - angle <- if(is.null(angle)) 0 else angle - vpc <- viewport(x=x, y=y, width=width, height=height, angle=angle, - xscale = c(0, ncol(Z)), yscale =c(0, nrow(Z))) - - if(raster){ - child <- rasterGrob(rast, vp=vpc, ...) - - } else { - child <- - imageGrob(nrow(Z), ncol(Z), cols=pic@col[Z], gp=gpar(col=pic@col[Z]), byrow=FALSE, vp=vpc, ...) - } - - gTree(width= width[[1]], - height = height[[1]], vp=vp, - children=gList(child), childrenvp=vpc, cl="pixmap") - -} - -##' @export -as.raster.pixmapRGB <- function(x) { - nr <- nrow(x@red) - r <- rgb((x@red), (x@green), (x@blue)) - dim(r) <- x@size - r -} - -##' read tiff files with pixmap -##' -##' @aliases as.raster.pixmapRGB read.tiff -##' @param con connection -##' @param ... unused -##' @return ... -##' @family userlevel -##' @export -## function obtained from Simon Urbanek -## to import tiff files in pixmap -## Thu Jun 5 16:15:40 CEST 2008 -## https://stat.ethz.ch/pipermail/r-sig-mac/2008-June/005047.html -## - -read.tiff <- function(con, ...) { - if (is.character(con)) { - con = file(con, "rb") - on.exit(close(con)) - } - sig = readBin(con, 1L, 1, 2) - if (sig != 0x4949 && sig != 0x4d4d) stop("Invalid signature") - end = if (sig == 0x4949) "little" else "big" - if (readBin(con, 1L, 1, 2, endian=end) != 42) stop("Invalid -signature") - o = readBin(con, 1L, 1, 4, endian=end) - data = readBin(con, 1L, o - 8, 1, signed=FALSE, endian=end) - ifds = readBin(con, 1L, 1, 2, endian=end) - info = list() - for (i in 1:ifds) { - tag = readBin(con, 1L, 6, 2, endian=end) - if (tag[1] == 257) info$height = tag[5] - if (tag[1] == 256) info$width = tag[5] - if (tag[1] == 259 && tag[5] != 1) stop("compressed TIFFs are not -supported") - } - if (is.null(info$width)||is.null(info$height)) stop("missing width/ -height tags") - res = array(data/255, dim=c(3, info$width, info$height)) - z = pixmapRGB(0, ncol = dim(res)[2], nrow = dim(res)[3], ...) - z@red = t(res[1, , ]) - z@green = t(res[2, , ]) - z@blue = t(res[3, , ]) - z -} - diff -Nru r-cran-gridextra-0.9-1/R/polygon.regular.r r-cran-gridextra-2.0.0/R/polygon.regular.r --- r-cran-gridextra-0.9-1/R/polygon.regular.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/polygon.regular.r 1970-01-01 00:00:00.000000000 +0000 @@ -1,127 +0,0 @@ -##' compute vertices of a convex polygon -##' -##' @aliases polygon1 polygon2 -##' @title polygon1 -##' @param n integer -##' @param ang numeric angle -##' @param ... unused -##' @return a data.frame -##' @examples -##' polygon2(5) - -polygon1 <- function(n=5, ang=0,...) { # inspired from a post by Greg Snow on r-help (11/09/09) - theta <- seq(ang, length.out=n+1, by=2*pi/n) - cbind( cumsum(cos(theta)/2), cumsum(sin(theta)/2) ) -} - -##' @export -polygon2 <- function(n=5, ang=0, x=0, y=0, rotateFromOrigin=FALSE){ - # inspired from a post by William Dunlap on r-help (10/09/09) -if(n<3) stop("n must be more than 3!") -#if(n>100) warning("n is limited to 100") - - cc <- exp(seq(0, n)*2i*pi/n) -if(rotateFromOrigin) - { - cc <- (cc + complex(x, y)) * exp(1i*ang) - } else { - cc <- cc * exp(1i*ang) + complex(x, y) - } - - cbind(Re(cc), Im(cc)) -} - - - - -##' compute vertices of a starred polygon -##' -##' @aliases polygon.star -##' @title polygon.star -##' @param n int -##' @param adj numeric angle -##' @param r radius -##' @return a data.frame -##' @export -##' @examples -##' polygon.star(5) - -polygon.star <- function(n=4, adj=pi/2, r=1){ - - if (n == 1) { - return(rbind(c(0, 0), c(cos(adj), sin(adj)) * r)) - } - if (n == 2) { - return(rbind(c(cos(adj), sin(adj)), c(cos(adj + pi), - sin(adj + pi))) * r) - } - if (n == 3) { - return(rbind(c(0, 0), c(cos(adj), sin(adj)), NA, c(0, - 0), c(cos(adj + 2 * pi/3), sin(adj + 2 * pi/3)), - NA, c(0, 0), c(cos(adj + 4 * pi/3), sin(adj + 4 * - pi/3))) * r) - } - if (n == 4) { - return(rbind(c(cos(adj), sin(adj)), c(cos(adj + pi), - sin(adj + pi)), NA, c(cos(adj + pi/2), sin(adj + - pi/2)), c(cos(adj + 3 * pi/2), sin(adj + 3 * pi/2))) * - r) - } - if (n == 6) { - tmp <- c(0, 2 * pi/3, 4 * pi/3, 2 * pi) - tmp <- c(tmp, NA, tmp + pi/3) + adj - return(cbind(cos(tmp), sin(tmp)) * r) - } - skp <- floor(n/2 - 0.1) - tmp <- seq(0, skp * 2 * pi, length.out = n + 1) + adj - tmp2 <- cbind(cos(tmp), sin(tmp)) * r - while (any(duplicated(round(tmp2[-1, ], 5)))) { - skp <- skp - 1 - tmp <- seq(0, skp * 2 * pi, length.out = n + 1) + adj - tmp2 <- cbind(cos(tmp), sin(tmp)) * r - } - return(tmp2) - -} - - -#' compute vertices of a polygon -#' -#' @aliases polygon.regular -#' @title polygon.regular -#' @param sides int -#' @param scale.area logical -#' @param star logical -#' @return a data.frame -#' @seealso \code{star} -#' @references ngon from the 'maptree' package -##' @export -#' @examples -#' polygon.regular(5) - -polygon.regular <- function (sides=4, scale.area=TRUE, star=FALSE) { - -n <- sides # lazy to replace -if (n<3) n <- 3 -if (n > 8) n <- 50 -# if (n > 8 & star) n <- 8 - -if(!star){ # convex polygon - -xy <- polygon2(n) - if(scale.area) { - Area = n/2 * 1^2 * sin(2*pi / n) - xy <- xy / sqrt(Area) - } - -} else { # starred version -xy <- polygon.star(n=sides) -if(scale.area) { - # unimplemented - .NotYetImplemented() -} - -} -return(xy) -} - diff -Nru r-cran-gridextra-0.9-1/R/rpattern.r r-cran-gridextra-2.0.0/R/rpattern.r --- r-cran-gridextra-0.9-1/R/rpattern.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/rpattern.r 1970-01-01 00:00:00.000000000 +0000 @@ -1,78 +0,0 @@ -tile.motif <- function(m, nx=10, ny=nx){ - cols <- matrix(rep(m, nx), ncol=ncol(m)*nx, byrow=FALSE) - matrix(rep(t(cols), ny), nrow=nrow(cols)*ny, byrow=TRUE) -} - -##' rectangular grob with raster fill pattern -##' -##' @aliases rpatternGrob tile.motif widthDetails.rpattern heightDetails.rpattern drawDetails.rpattern grid.rpattern -##' @title rpatternGrob -##' @param x x unit -##' @param y y unit -##' @param width width -##' @param height height -##' @param motif motif -##' @param AR AR -##' @param motif.width motif.width -##' @param motif.height motif.height -##' @param pattern.offset pattern.offset -##' @param default.units default.units -##' @param clip clip -##' @param gp gp -##' @param ... additional params passed to the grob -##' @return grob of class rpattern -##' @family grob userlevel -##' @export -##' -##' @examples -##' .lines45 <- matrix("white", ncol=100, nrow=100) -##' diag(.lines45) <- "black" -##' grid.rpattern(motif=.lines45) - -rpatternGrob <- function(x=unit(0.5, "npc"), y=unit(0.5, "npc"), - width=unit(1, "npc"), height=unit(1, "npc"), - motif=matrix("white"), AR=1, - motif.width=unit(5, "mm"), - motif.height=AR*motif.width, - pattern.offset=c(0, 0), # unimplemented - default.units="npc", - clip=TRUE, gp=gpar(fill=NA), ...) - { - grob(x=x, y=y, width=width, height=height, - motif=motif, motif.width=motif.width, - motif.height=motif.height, clip=clip, gp=gp, ..., cl="rpattern") - } - -##' @export -widthDetails.rpattern <- function(x) x$width -##' @export -heightDetails.rpattern <- function(x) x$height - -##' @export -drawDetails.rpattern <- function(x, recording=TRUE){ - -## calculate the number of tiles - nx <- ceiling(convertUnit(x$width, "in", valueOnly=TRUE) / - convertUnit(x$motif.width, "in", valueOnly=TRUE)) + 1 - ny <- ceiling(convertUnit(x$height, "in", axisFrom = "y", valueOnly=TRUE) / - convertUnit(x$motif.height, "in", axisFrom = "y", valueOnly=TRUE)) + 1 - -## clip the raster - pushViewport(viewport(x=x$x, y=x$y, - width=x$width, height=x$height, clip=x$clip)) - - grid.raster(tile.motif(x$motif, nx, ny), width=nx*x$motif.width, - height=ny*x$motif.height, interpolate = TRUE) - upViewport() - -## overlay the rectangle - grid.rect(x=x$x, y=x$y, - width=x$width, height=x$height, - just="center", gp=x$gp) -} - - - -##' @export -grid.rpattern <- function(...) - grid.draw(rpatternGrob(...)) diff -Nru r-cran-gridextra-0.9-1/R/stextGrob.r r-cran-gridextra-2.0.0/R/stextGrob.r --- r-cran-gridextra-0.9-1/R/stextGrob.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/stextGrob.r 1970-01-01 00:00:00.000000000 +0000 @@ -1,59 +0,0 @@ - -##' shadow text -##' -##' adds a blurred white version of a label below the text -##' @title stextGrob -##' @aliases stextGrob grid.stext -##' @param label see textGrob -##' @param r blur radius -##' @param x see textGrob -##' @param y see textGrob -##' @param just see textGrob -##' @param hjust see textGrob -##' @param vjust see textGrob -##' @param rot see textGrob -##' @param check.overlap see textGrob -##' @param default.units see textGrob -##' @param name see textGrob -##' @param gp see textGrob -##' @param vp see textGrob -##' @return gTree -##' @author Baptiste Auguie -##' @family grob userlevel -##' @export -##' @examples -##' grid.rect(gp=gpar(fill="grey")) -##' grid.stext("test") -stextGrob <- function (label, r=0.1, x = unit(0.5, "npc"), y = unit(0.5, "npc"), - just = "centre", hjust = NULL, vjust = NULL, rot = 0, check.overlap = FALSE, - default.units = "npc", name = NULL, gp = gpar(), vp = NULL){ - - let <- textGrob("a") - - tg <- textGrob(label=label, x=x, y=y, gp=gpar(col="black"), - just = just, hjust = hjust, vjust = vjust, rot = rot, - check.overlap = check.overlap, - default.units = default.units) - - tgl <- c(lapply(seq(0, 2*pi, length=18), function(theta){ - - textGrob(label=label,x=x+cos(theta)*r*grobWidth(let), - y=y+sin(theta)*r*grobHeight(let), gp=gpar(col="white"), - just = just, hjust = hjust, vjust = vjust, rot = rot, - check.overlap = check.overlap, - default.units = default.units) - - }), list(tg)) - - - g <- gTree(children=do.call(gList, tgl), vp=vp, name=name, gp=gp) - -} - -##' @export -grid.stext <- function(...){ - g <- stextGrob(...) - grid.draw(g) - invisible(g) -} - diff -Nru r-cran-gridextra-0.9-1/R/tableGrob.r r-cran-gridextra-2.0.0/R/tableGrob.r --- r-cran-gridextra-0.9-1/R/tableGrob.r 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/R/tableGrob.r 2015-07-14 08:59:13.000000000 +0000 @@ -1,457 +1,230 @@ -## create a named cell grob -## a function of an integer index that returns a named grob - -textii <- function(d, gp=gpar(), name="row-label-", - just="center", parse=TRUE){ - x <- switch(just, "center"=0.5, "right"=0.95, "left"=0.1) - parseglobal <- parse - ## allow the correct space to fit well in a rectangle - function(ii, parse=parseglobal){ - lab <- if(parse) parse(text=d[ii]) else d[ii] - textGrob(x=x, label=lab, just=just, gp=gp, name=paste(name, ii, sep="")) - } -} - -rectii <- function(ii, gp, name="row-fill-"){ - function(ii) - rectGrob(gp=gp[[ii]], name=paste(name, ii, sep="")) -} - -makeTableGrobs <- function(content, rnames=NULL, cnames=NULL, - nrow, ncol, parse=TRUE, - row.just="center", col.just="center", core.just="center", - equal.width = FALSE, equal.height=FALSE, - gpar.coretext = gpar(col="black", cex=1), - gpar.coltext = gpar(col="black", cex=1, fontface="bold"), - gpar.rowtext = gpar(col="black", cex=0.8, fontface="italic"), - h.odd.alpha = 1, h.even.alpha = 1, - v.odd.alpha = 1, v.even.alpha = 1, - gpar.corefill = gpar(fill = "grey95", col="white"), - gpar.rowfill = gpar(fill = "grey90", col="white"), - gpar.colfill = gpar(fill = "grey90", col="white")) { - - ncontent <- length(content) # number of labels - nrnames <- length(rnames) # number of row labels - ncnames <- length(cnames) # number of col labels - - - ## define some functions to generate named grobs - makeOneRowname <- textii(d=rnames, gp=gpar.rowtext, name="row-label-", just=row.just, parse=parse) - makeOneColname <- textii(d=cnames, gp=gpar.coltext, name="col-label-", just=col.just, parse=parse) - makeOneLabel <- textii(d=content, gp=gpar.coretext, name="core-label-", just=core.just, parse=parse) - - - gp.corefillee <- gp.corefilleo <- gp.corefilloe <- gp.corefilloo <- gpar.corefill - gp.corefillee[["alpha"]] <- h.even.alpha * v.even.alpha - gp.corefilloe[["alpha"]] <- h.odd.alpha * v.even.alpha - gp.corefilloo[["alpha"]] <- h.odd.alpha * v.odd.alpha - gp.corefilleo[["alpha"]] <- h.even.alpha * v.odd.alpha - - gpar.corefill <- rep(c(rep(c(list(gp.corefillee), list(gp.corefilloe)), length.out=nrow), - rep(c(list(gp.corefilleo), list(gp.corefilloo)), length.out=nrow)), - length.out=ncontent) - - gp.rowfille <- gp.rowfillo <- gpar.rowfill - gp.rowfille[["alpha"]] <- h.even.alpha - gp.rowfillo[["alpha"]] <- h.odd.alpha - - gpar.rowfill <- rep(c(list(gp.rowfille), list(gp.rowfillo)), nrow) - - gp.colfille <- gp.colfillo <- gpar.colfill - gp.colfille[["alpha"]] <- v.even.alpha - gp.colfillo[["alpha"]] <- v.odd.alpha - - gpar.colfill <- rep(c(list(gp.colfille), list(gp.colfillo)), ncol) - - makeOneCell <- rectii(gp=gpar.corefill, name="core-fill-") - makeOneRowfill <- rectii(gp=gpar.rowfill, name="row-fill-") - makeOneColfill <- rectii(gp=gpar.colfill, name="col-fill-") - - ## in case of missing row(col) names, make a list of virtualGrobs - ## else, a list of rectGrobs with incremental names - if(is.null(rnames)){ - lrt <- lrf <- replicate(nrow, virtualGrob, simplify=FALSE)} else { - lrt <- lapply(seq_along(rnames), makeOneRowname) # list of text grobs - lrf <- lapply(seq_along(rnames), makeOneRowfill) # list of rect grobs - } - if(is.null(cnames)){ - lct <- lcf <- replicate(ncol, virtualGrob, simplify=FALSE)} else { - lct <- lapply(seq_along(cnames), makeOneColname) # list of text grobs - lcf <- lapply(seq_along(cnames), makeOneColfill) # list of rect grobs - } - ## the content consists of textGrobs and rectGrobs - lit <- lapply(seq_along(content), makeOneLabel) # list of text grobs - lif <- lapply(seq_along(content), makeOneCell) # list of rect grobs - - ## here the grobs are arranged and permuted in a list to fill a matrix column by column - lgt <- c(list(virtualGrob), lrt, interleaven(lct, lit, nrow)) # all labels in order - lgf <- c(list(virtualGrob), lrf, interleaven(lcf, lif, nrow)) # all labels in order - - ## retrieve the widths and heights of all textGrobs (including some virtualGrobs) - wg <- lapply(lgt, grobWidth) # list of grob widths - hg <- lapply(lgt, grobHeight) # list of grob heights - - ## concatenate this units - widths.all <- do.call(unit.c, wg) # all grob widths - heights.all <- do.call(unit.c, hg) #all grob heights - - ## matrix-like operations on units to define the table layout - widths <- colMax.units(widths.all, ncol+1) # all column widths - heights <- rowMax.units(heights.all, nrow+1) # all row heights - - ## equal width or equal height (all except rows and cols) - nwidths <- length(widths) - nheights <- length(heights) - if(equal.width) - widths <- unit.c(widths[[1]], rep(max(widths[seq(2, nwidths)]), nwidths-1)) - if(equal.height) - heights <- unit.c(heights[[1]], rep(max(heights[seq(2, nheights)]), nheights-1)) - - ## return a list containing lists of grobs, and the dimensions for a rectangular layout - list(lgt=lgt, lgf=lgf, nrow=nrow, ncol=ncol, widths=widths, heights=heights) -} - - -arrangeTableGrobs <- function(lgt, lgf, nrow, ncol, widths, heights, - show.colnames, show.rownames, - padding.h = unit(4, "mm"), padding.v=unit(4, "mm"), - just=c("center", "center"), separator= "white", - show.vlines=FALSE, show.hlines=FALSE, show.namesep=FALSE, - show.box=FALSE, show.csep=FALSE, show.rsep=FALSE){ - - label.ind <- 1 # index running accross labels - - ## loop over columns and rows - for (ii in seq(1, ncol+1, 1)) { - for (jj in seq(1, nrow+1, 1)) { - ## push a viewport for cell (ii,jj) - pushViewport(vp=viewport( layout.pos.row=jj, layout.pos.col=ii, just=just)) - grid.draw( lgf[[label.ind]]) #draw the fill - grid.draw( lgt[[label.ind]]) #draw the text - upViewport() - - label.ind <- label.ind + 1 - } - } - - if(show.hlines){ - ## draw horizontal lines, stopping or not before the names - for (ii in seq(2, nrow, 1)) - grid.segments(0, 0, 1, 0, gp=gpar(col=separator), vp=viewport( layout.pos.row=ii, - layout.pos.col=seq(1+!show.rsep, ncol+1))) - } - if(show.vlines){ - ## draw vertical lines, stopping or not before the names - for (jj in seq(2, ncol, 1)) - grid.segments(1, 0, 1, 1, gp=gpar(col=separator), vp=viewport( layout.pos.col=jj, - layout.pos.row=seq(1+!show.csep, nrow+1))) - } - ## draw box around the content (and the names if present) - if(show.box){ - if(show.colnames & show.rownames){ - grid.border(type=16, colour=separator, - vp=viewport( layout.pos.col=seq(2, ncol+1), layout.pos.row=seq(2, nrow+1))) - } else - grid.rect(gp=gpar(col=separator, fill=NA), - vp=viewport( layout.pos.col=seq(1, ncol+1), layout.pos.row=seq(1, nrow+1))) - } - - if(show.namesep){ - ## draw corner, style depends on the presence of row/colnames - type <- if(show.colnames & show.rownames) 8 else - if(show.colnames & !show.rownames) 4 else - if(!show.colnames & show.rownames) 5 else 1 - - grid.border(type=type, colour=separator, - vp=viewport( layout.pos.col=seq(2, ncol+1), layout.pos.row=seq(2, nrow+1))) - } - - -} - - -##' create a list of text and fill grobs and calculates the sizes for a table display -##' -##' @aliases tableGrob grid.table drawDetails.table widthDetails.table heightDetails.table arrangeTableGrobs makeTableGrobs -##' @title tableGrob -##' @param d data.frame -##' @param rows vector of row names -##' @param cols vector of col names -##' @param parse logical, parse labels as expressions -##' @param row.just justification of labels -##' @param col.just justification of labels -##' @param core.just justification of labels -##' @param separator colour of the border lines -##' @param show.box logical box surrounding the table -##' @param show.vlines logical vertical lines -##' @param show.hlines logical horizontal lines -##' @param show.namesep logical draw lines to separate header(s) -##' @param show.csep logical extend vert. separator to colnames -##' @param show.rsep logical extend vert. separator to rownames -##' @param equal.width logical -##' @param equal.height logical -##' @param padding.h unit of horizontal margin, per cell -##' @param padding.v unit of vertical margin, per cell -##' @param gpar.coretext gpar() for inner text -##' @param gpar.corefill gpar() for inner fill -##' @param gpar.coltext gpar() for colnames text -##' @param h.odd.alpha numeric transparency factor for odd horizontal cells -##' @param h.even.alpha numeric transparency factor for even horizontal cells -##' @param v.odd.alpha numeric transparency factor for odd vertical cells -##' @param v.even.alpha numeric transparency factor for even vertical cells -##' @param gpar.colfill gpar() for colnames fill -##' @param gpar.rowtext gpar() for rownames text -##' @param gpar.rowfill gpar() for rownames fill -##' @param show.rownames logical -##' @param show.colnames logical -##' @param gp gpar -##' @param theme theme (list of aesthetic elements) -##' @param ... passed to grob -##' @return a grob of class table -##' @family grob userlevel -##' @export -##' -##' @examples -##' grid.table(head(iris), h.even.alpha=1, h.odd.alpha=1, v.even.alpha=0.5, v.odd.alpha=1) -##' grid.newpage() -##' grid.draw(tableGrob(head(iris, 10), name="test")) -##' e = expression(alpha,"testing very large width", hat(beta), integral(f(x)*dx, a, b), "abc") -##' grid.edit("test", cols=e, show.rownames=FALSE, rows=NULL, -##' gpar.corefill = gpar(fill="white", col=NA), -##' grep=TRUE, global=TRUE) -##' grid.newpage() -##' grid.draw(tableGrob(head(iris, 10), -##' show.csep=TRUE, show.rsep=TRUE, show.box=TRUE, separator="grey", name="test")) -##' grid.edit("test",gp=gpar(fontsize=8, lwd=2), equal.width=TRUE, grep=TRUE, global=TRUE) -##' # visualize themes -##' lg <- lapply(c("theme.blank", "theme.default", "theme.white", "theme.vertical", "theme.list", "theme.black"), -##' function(x) tableGrob(head(iris[, 1:3]), theme=get(x)())) -##' grid.newpage() -##' do.call(grid.arrange, lg) -##' \dontrun{ -##' ## timing: a bit slow due to repeated on-the-fly calculations -##' pdf("test2.pdf", height=50) -##' print(system.time( grid.table(iris)) ) # about 12s here -##' dev.off() -##' } - - -tableGrob <- function(d, rows=rownames(d), cols=colnames(d), parse=FALSE, - show.rownames=TRUE, show.colnames=TRUE, - row.just="center", col.just="center", core.just="center", - separator="white", show.box=FALSE, show.vlines=FALSE, show.hlines=FALSE, - show.namesep=FALSE, show.csep=FALSE, show.rsep=FALSE, - equal.width = FALSE, equal.height=FALSE, - padding.h = unit(4, "mm"), padding.v=unit(4, "mm"), - gp=NULL, - gpar.coretext = gpar(col="black", cex=1), - gpar.coltext = gpar(col="black", cex=1, fontface="bold"), - gpar.rowtext = gpar(col="black", cex=0.8, fontface="italic"), - h.odd.alpha = 1, h.even.alpha = 1, - v.odd.alpha = 1, v.even.alpha = 1, - gpar.corefill = gpar(fill = "grey95", col="white"), - gpar.rowfill = gpar(fill = "grey90", col="white"), - gpar.colfill = gpar(fill = "grey90", col="white"), theme=NULL, - ...) { - - ## this needs to be done later in case a theme is used - ## if(!show.rownames) rows <- NULL - ## if(!show.colnames) cols <- NULL - - lg <- - with(theme, - makeTableGrobs(as.character(as.matrix(d)), rows, cols, parse=parse, - NROW(d), NCOL(d), - row.just = row.just, col.just = col.just, core.just = core.just, - equal.width = equal.width, equal.height = equal.height, - gpar.coretext = gpar.coretext, - gpar.coltext = gpar.coltext, - gpar.rowtext = gpar.rowtext, - h.odd.alpha = h.odd.alpha, h.even.alpha = h.even.alpha, - v.odd.alpha = v.odd.alpha, v.even.alpha = v.even.alpha, - gpar.corefill = gpar.corefill, - gpar.rowfill = gpar.rowfill, - gpar.colfill = gpar.colfill )) - - with(theme, # params provided as a list - gTree(lg=lg, d=d, rows= if(show.rownames) rows, cols=if(show.colnames) cols, parse=parse, - show.rownames=show.rownames, show.colnames=show.colnames, - row.just = row.just, col.just = col.just, core.just = core.just, - separator=separator, show.box=show.box, - show.vlines=show.vlines, show.hlines=show.hlines, show.namesep=show.namesep, - show.csep=show.csep, show.rsep=show.rsep, - equal.width = equal.width, equal.height = equal.height, - padding.h = padding.h, padding.v = padding.v, - gpar.coretext = gpar.coretext, - gpar.coltext = gpar.coltext, - gpar.rowtext = gpar.rowtext, - h.odd.alpha = h.odd.alpha, h.even.alpha = h.even.alpha, - v.odd.alpha = v.odd.alpha, v.even.alpha = v.even.alpha, - gpar.corefill = gpar.corefill, - gpar.rowfill = gpar.rowfill, - gpar.colfill = gpar.colfill, - cl="table", gp=gp, ...)) - -} - - -##' @export +#' @aliases grid.table tableGrob ttheme_default, ttheme_minimal +#' @title Graphical display of a textual table +#' @describeIn tableGrob return a grob +#' @description Create a gtable containing text grobs representing a character matrix +#' @param d data.frame or matrix +#' @param rows optional vector to specify row names +#' @param cols optional vector to specify column names +#' @param theme list of theme parameters +#' @param ... further arguments to control the gtable +#' @return a gtable +#' @export +#' @examples +#' library(grid) +#' d <- head(iris, 3) +#' g <- tableGrob(d) +#' grid.newpage() +#' grid.draw(g) +tableGrob <- function(d, rows=rownames(d), cols=colnames(d), + theme = ttheme_default(), + ...){ + + + g <- gtable_table(d, name="core", + fg_params = theme$core$fg_params, + bg_params = theme$core$bg_params, + padding=theme$core$padding, ...) + + if(!is.null(cols)){ + gc <- gtable_table(t(cols), name="colhead", + fg_params = theme$colhead$fg_params, + bg_params = theme$colhead$bg_params, + padding=theme$colhead$padding) + g <- rbind_gtable(gc, g) + } + if(!is.null(rows)){ + if(!is.null(cols)) # need to add dummy cell + rows <- c("", rows) + gr <- gtable_table(rows, name="rowhead", + fg_params = theme$rowhead$fg_params, + bg_params = theme$rowhead$bg_params, + padding=theme$rowhead$padding) + g <- cbind_gtable(gr, g) + } + + g +} + +#' @describeIn tableGrob draw a text table +#' @inheritParams tableGrob +#' @export grid.table <- function(...) grid.draw(tableGrob(...)) -##' @export -drawDetails.table <- function(x, recording=TRUE){ +#' @describeIn tableGrob default theme for text tables +#' @inheritParams tableGrob +#' @importFrom utils modifyList +##' @export +ttheme_default <- function(...){ + + core <- list(fg_fun = text_grob, + fg_params = list(parse=FALSE, col="black"), + bg_fun = rect_grob, + bg_params = list(fill = c("grey95","grey90"), + lwd=1.5, col="white"), + padding = unit(c(4, 4), "mm")) + + colhead <- list(fg_fun = text_grob, + fg_params = list(parse=FALSE, fontface=2L), + bg_fun = rect_grob, + bg_params = list(fill = c("grey80"), + lwd=1.5, col="white"), + padding = unit(c(4, 4), "mm")) + + rowhead <- list(fg_fun = text_grob, + fg_params = list(parse=FALSE, fontface=3L), + bg_fun = rect_grob, + bg_params = list(fill=NA, col=NA), + padding = unit(c(4, 4), "mm")) + + default <- list( + core = core, + colhead = colhead, + rowhead= rowhead + ) + + modifyList(default, list(...)) - lg <- with(x, makeTableGrobs(as.character(as.matrix(d)), rows, cols, - NROW(d), NCOL(d), parse, - row.just = row.just, col.just = col.just, core.just = core.just, - equal.width = equal.width, equal.height = equal.height, - gpar.coretext = gpar.coretext, - gpar.coltext = gpar.coltext, - gpar.rowtext = gpar.rowtext, - h.odd.alpha = h.odd.alpha, h.even.alpha = h.even.alpha, - v.odd.alpha = v.odd.alpha, v.even.alpha = v.even.alpha, - gpar.corefill = gpar.corefill, - gpar.rowfill = gpar.rowfill, - gpar.colfill = gpar.colfill ) ) - - widthsv <- convertUnit(lg$widths + x$padding.h, "mm", valueOnly=TRUE) - heightsv <- convertUnit(lg$heights + x$padding.v, "mm", valueOnly=TRUE) - - widthsv[1] <- widthsv[1] * as.numeric(x$show.rownames) - widths <- unit(widthsv, "mm") - - heightsv[1] <- heightsv[1] * as.numeric(x$show.colnames) - heights <- unit(heightsv, "mm") - - cells = viewport(name="table.cells", layout = - grid.layout(lg$nrow+1, lg$ncol+1, widths=widths, heights=heights) ) - - pushViewport(cells) - tg <- arrangeTableGrobs(lg$lgt, lg$lgf, lg$nrow, lg$ncol, lg$widths, lg$heights, - show.colnames=x$show.colnames, show.rownames=x$show.rownames, - padding.h = x$padding.h, padding.v = x$padding.v, - separator=x$separator, show.box=x$show.box, - show.vlines=x$show.vlines, show.hlines=x$show.hlines, - show.namesep=x$show.namesep, show.csep=x$show.csep, show.rsep=x$show.rsep) - upViewport() } -##' @export -widthDetails.table <- function(x){ - lg <- x$lg - widthsv <- convertUnit(lg$widths + x$padding.h, "mm", valueOnly=TRUE) - widthsv[1] <- widthsv[1] * as.numeric(x$show.rownames) - widths <- unit(widthsv, "mm") - - sum(widths) -} - -##' @export -heightDetails.table <- function(x){ - lg <- x$lg - heightsv <- convertUnit(lg$heights + x$padding.v, "mm", valueOnly=TRUE) - heightsv[1] <- heightsv[1] * as.numeric(x$show.colnames) - heights <- unit(heightsv, "mm") - sum(heights) +#' @describeIn tableGrob minimalist theme for text tables +#' @inheritParams tableGrob +##' @export +ttheme_minimal <- function(...){ + + core <- list(fg_fun = text_grob, + fg_params = list(parse=FALSE, col="black"), + bg_fun = rect_grob, + bg_params = list(fill = NA, col=NA), + padding = unit(c(4, 4), "mm")) + + colhead <- list(fg_fun = text_grob, + fg_params = list(parse=FALSE, fontface=2L), + bg_fun = rect_grob, + bg_params = list(fill = NA, col=NA), + padding = unit(c(4, 4), "mm")) + + rowhead <- list(fg_fun = text_grob, + fg_params = list(parse=FALSE, fontface=3L, + hjust = 1, x = 0.95), + bg_fun = rect_grob, + bg_params = list(fill=NA, col=NA), + padding = unit(c(4, 4), "mm")) + + default <- list( + core = core, + colhead = colhead, + rowhead= rowhead + ) + + modifyList(default, list(...)) + +} + +text_grob <- function(label, + parse=FALSE, + col = "black", + fontsize = 12, + cex = 1, + fontfamily = "", + fontface = 1L, + lineheight = 1.2, + alpha = 1, + rot = 0, + just = "centre", + hjust = 0.5, + vjust = 0.5, + x = 0.5, + y = 0.5){ + if(parse){ + label <- tryCatch(parse(text=label), + error = function(e) label) + } + textGrob(label = label, x = x, y = y, + just = just, hjust = hjust, vjust = vjust, + rot = rot, + gp = gpar(col = col, + fontsize = fontsize, + cex = cex, + fontfamily = fontfamily, + fontface = fontface, + lineheight = lineheight, + alpha = alpha)) +} + + +rect_grob <- function(fill = "white", + col = "black", + lty = "solid", + lwd = 1, cex = 1, + alpha = 1, + lineend = "round", + linejoin = "round", + linemitre = 10, lex = 1){ + + rectGrob(width = unit(1,"npc") - unit(2, "scaledpts"), + height = unit(1,"npc") - unit(2, "scaledpts"), + gp = gpar(col = col, + fill = fill, + lty = lty, + lwd = lwd, cex = cex, + alpha = alpha, + lineend = lineend, + linejoin = linejoin, + linemitre = linemitre, lex = lex, + alpha = alpha)) +} + + +## +## unexported helper functions +## +gtable_table <- function(d, widths, heights, + fg_fun = text_grob, fg_params = list(), + bg_fun = rect_grob, bg_params = list(), + padding = unit(c(4, 4), "mm"), + name = "table", vp = NULL){ + + label_matrix <- as.matrix(d) + + nc <- ncol(label_matrix) + nr <- nrow(label_matrix) + n <- nc*nr + + fg_params <- lapply(fg_params, rep, length.out = n, each = nc) + bg_params <- lapply(bg_params, rep, length.out = n, each = nc) + + fg_params <- data.frame(fg_params, + label = as.vector(label_matrix), + stringsAsFactors=FALSE) + bg_params <- data.frame(bg_params, stringsAsFactors=FALSE) + labels <- do.call(mapply, c(fg_params, list(FUN = fg_fun, + SIMPLIFY=FALSE))) + bkgds <- do.call(mapply, c(bg_params, list(FUN = bg_fun, + SIMPLIFY=FALSE))) + + label_grobs <- matrix(labels, ncol = nc) + + ## some calculations of cell sizes + + if(missing(widths)) + widths <- col_widths(label_grobs) + padding[1] + if(missing(heights)) + heights <- row_heights(label_grobs) + padding[2] + + ## place labels in a gtable + g <- gtable_matrix(paste0(name, "-fg"), grobs=label_grobs, + widths = widths, + heights = heights, vp=vp) + + ## add the background + g <- gtable_add_grob(g, bkgds, + t=rep(seq_len(nr), each=nc), + l=rep(seq_len(nc), nr), z=0, + name=paste0(name, "-bg")) + + g } - - -##' themes for table grob -##' @aliases theme.default theme.grey theme.list theme.blank theme.vertical theme.black theme.white -##' @title theme -##' @param ... optional params to overwrite the theme defaults -##' @return theme -##' @export -theme.default <- theme.grey <- function(...) - modifyList(list(show.rownames=TRUE, show.colnames=TRUE, - row.just="center", col.just="center", core.just="center", - separator="white", show.box=FALSE, show.vlines=FALSE, show.hlines=FALSE, show.namesep=FALSE, - show.csep=FALSE, show.rsep=FALSE, - equal.width = FALSE, equal.height=FALSE, - padding.h = unit(4, "mm"), padding.v=unit(4, "mm"), - gp=NULL, - gpar.coretext = gpar(col="black", cex=1), - gpar.coltext = gpar(col="black", cex=1, fontface="bold"), - gpar.rowtext = gpar(col="black", cex=0.8, fontface="italic"), - h.odd.alpha = 1, h.even.alpha = 1, - v.odd.alpha = 1, v.even.alpha = 1, - gpar.corefill = gpar(fill = "grey95", col="white"), - gpar.rowfill = gpar(fill = "grey90", col="white"), - gpar.colfill = gpar(fill = "grey90", col="white")), list(...)) - - -##' @export -theme.list <- function(...) - modifyList( - theme.default(show.rownames=FALSE, show.colnames=FALSE, separator=NA, - core.just="left", gpar.corefill=gpar(col=NA), - show.csep=FALSE, show.rsep=FALSE, - gpar.corefill = gpar(fill = NA, col=NA), - gpar.rowfill = gpar(fill = NA, col=NA), - gpar.colfill = gpar(fill = NA, col=NA)), list(...)) - - -##' @export -theme.black <- function(...) - modifyList( - theme.default(show.rownames=TRUE, show.colnames=TRUE, - separator="white", - h.odd.alpha = 0.8, h.even.alpha = 0.5, - show.csep=TRUE, show.rsep=TRUE, - gpar.coretext = gpar(col="white", cex=1), - gpar.coltext = gpar(col="white", cex=1, fontface="bold"), - gpar.rowtext = gpar(col="white", cex=0.8, fontface="italic"), - gpar.corefill = gpar(fill = "black", col=NA), - gpar.rowfill = gpar(fill = "black", col=NA), - gpar.colfill = gpar(fill = "black", col=NA)), list(...)) - -##' @export -theme.blank <- function(...) - modifyList( - theme.default(show.rownames=TRUE, show.colnames=TRUE, - gpar.corefill=gpar(col=NA),separator=NA, - show.csep=FALSE, show.rsep=FALSE, - gpar.corefill = gpar(fill = NA, col=NA), - gpar.rowfill = gpar(fill = NA, col=NA), - gpar.colfill = gpar(fill = NA, col=NA)), list(...)) - - -##' @export -theme.vertical <- function(...) - modifyList( - theme.default(show.rownames=FALSE, show.colnames=TRUE, - row.just="center", col.just="center", core.just="center", - separator="white", show.box=FALSE, show.csep=FALSE, show.rsep=FALSE, - equal.width = FALSE, equal.height=FALSE, - padding.h = unit(4, "mm"), padding.v=unit(4, "mm"), - gpar.coretext = gpar(col="black", cex=1), - gpar.coltext = gpar(col="black", cex=1, fontface="bold"), - gpar.rowtext = gpar(col="black", cex=0.8, fontface="italic"), - h.odd.alpha = 1, h.even.alpha = 1, - v.odd.alpha = 0.5, v.even.alpha = 0, - gpar.corefill = gpar(fill = "grey90", col=NA), - gpar.rowfill = gpar(fill = "grey90", col=NA), - gpar.colfill = gpar(fill = "grey90", col=NA)), list(...)) - - -##' @export -theme.white <- function(...) - modifyList( - theme.default(show.rownames=FALSE, show.colnames=TRUE, - row.just="center", col.just="center", core.just="center", - separator="white", show.box=FALSE, show.csep=FALSE, show.rsep=FALSE, - equal.width = FALSE, equal.height=FALSE, - padding.h = unit(4, "mm"), padding.v=unit(4, "mm"), - gpar.coretext = gpar(col="black", cex=1), - gpar.coltext = gpar(col="black", cex=1, fontface="bold"), - gpar.rowtext = gpar(col="black", cex=0.8, fontface="italic"), - h.odd.alpha = 0.5, h.even.alpha = 0, - v.odd.alpha = 1, v.even.alpha = 1, - gpar.corefill = gpar(fill = "grey90", col=NA), - gpar.rowfill = gpar(fill = "grey90", col=NA), - gpar.colfill = gpar(fill = "grey90", col=NA)), list(...)) - diff -Nru r-cran-gridextra-0.9-1/README.md r-cran-gridextra-2.0.0/README.md --- r-cran-gridextra-0.9-1/README.md 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/README.md 2015-07-11 10:27:22.000000000 +0000 @@ -0,0 +1,7 @@ +[![DOI](https://zenodo.org/badge/5734/baptiste/gridextra.png)](http://dx.doi.org/10.5281/zenodo.11422) +[![Build Status](https://travis-ci.org/baptiste/gridextra.svg?branch=master)](https://travis-ci.org/baptiste/gridextra) +[![](http://www.r-pkg.org/badges/version/gridExtra)](http://cran.rstudio.com/web/packages/gridExtra/index.html) +[![](http://cranlogs.r-pkg.org/badges/grand-total/gridExtra)](http://cran.rstudio.com/web/packages/gridExtra/index.html) + + +Provides a number of user-level functions to work with "grid" graphics, notably to arrange multiple grid-based plots on a page, and draw tables. Earlier versions of the package contained more experimental graphical objects (grobs), that have now been removed. \ No newline at end of file diff -Nru r-cran-gridextra-0.9-1/.Rinstignore r-cran-gridextra-2.0.0/.Rinstignore --- r-cran-gridextra-0.9-1/.Rinstignore 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/.Rinstignore 2015-07-11 00:51:53.000000000 +0000 @@ -0,0 +1 @@ +testing/ diff -Nru r-cran-gridextra-0.9-1/TODO r-cran-gridextra-2.0.0/TODO --- r-cran-gridextra-0.9-1/TODO 2012-01-29 19:53:23.000000000 +0000 +++ r-cran-gridextra-2.0.0/TODO 2015-07-09 06:24:19.000000000 +0000 @@ -1,12 +1,3 @@ -KNOWN BUGS - -* patternGrob ignores the linetype argument except for the first object drawn - -ENHANCEMENTS - -* tableGrob cannot be edited at low level (earlier versions could, but are incompatible with on-the-fly drawDetails method) - -* rewrite tableGrob using gtable NEW FEATURES diff -Nru r-cran-gridextra-0.9-1/vignettes/arrangeGrob.rmd r-cran-gridextra-2.0.0/vignettes/arrangeGrob.rmd --- r-cran-gridextra-0.9-1/vignettes/arrangeGrob.rmd 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/vignettes/arrangeGrob.rmd 2015-07-13 09:37:38.000000000 +0000 @@ -0,0 +1,91 @@ +--- +title: "Arranging multiple grobs on a page" +author: "Baptiste Auguie" +date: '`r Sys.Date()`' +vignette: > + %\VignetteEngine{knitr::rmarkdown} + %\VignetteIndexEntry{arrangeGrob: arranging multiple grobs on a page} +output: + knitr:::html_vignette: + toc: yes +--- + +```{r setup, echo=FALSE, results='hide'} +library(knitr) +opts_chunk$set(message=FALSE, fig.width=4, fig.height=3) +``` + +The `grid` package provides low-level functions to create graphical objects (`grobs`), and position them on a page in specific `viewports`. The `gtable` package introduced a higher-level layout scheme, arguably more amenable to user-level interaction. With the `arrangeGrob/grid.arrange()` pair of functions, `gridExtra` builds upon `gtable` to arrange multiple grobs on a page. + +## Basic usage + +In this example we mix a few grobs and plots, +```{r basic} +library(gridExtra) +library(grid) +library(ggplot2) +library(lattice) +p <- qplot(1,1) +p2 <- xyplot(1~1) +r <- rectGrob(gp=gpar(fill="grey90")) +t <- textGrob("text") +grid.arrange(t, p, p2, r, ncol=2) +``` + +## Title and/or annotations + +```{r annotations} +gs <- lapply(1:9, function(ii) + grobTree(rectGrob(gp=gpar(fill=ii, alpha=0.5)), textGrob(ii))) +grid.arrange(grobs=gs, ncol=4, + top="top label", bottom="bottom\nlabel", + left="left label", right="right label") +grid.rect(gp=gpar(fill=NA)) +``` + +## Complex layouts + +We can provide a matrix defining the layout, + +```{r layout} +lay <- rbind(c(1,1,1,2,3), + c(1,1,1,4,5), + c(6,7,8,9,9)) +grid.arrange(grobs = gs, layout_matrix = lay) +``` + +All cells are of equal size by default, but users may pass explicity `widths` and/or `heights` in any valid grid units, or as relative numbers (interpreted as `null`), + +```{r sizes, fig.height=2} +grid.arrange(grobs=gs[1:3], ncol=2, widths = 1:2, + heights=unit(c(1,10), c("in", "mm"))) +``` + +## Nested layouts with `arrangeGrob` + +The `grid.arrange()` function draws on the device; for more complex layouts, we may want to store the gtable and combine it with other objects, e.g. forming nested layouts. To this end, use `arrangeGrob()`, + +```{r grob} +g1 <- arrangeGrob(grobs = gs, layout_matrix = t(lay)) +g2 <- arrangeGrob(grobs = gs, layout_matrix = lay) +grid.arrange(g1, g2, ncol=2) +``` + +## Multiple pages output + +Finally, we may want to place grobs on multiple pages; the `marrangeGrob()` function provides a convenient interface for this, also compatible with `ggsave()`. + + +```{r marrange} +set.seed(123) +pl <- lapply(1:11, function(.x) + qplot(1:10, rnorm(10), main=paste("plot", .x))) +ml <- marrangeGrob(pl, nrow=2, ncol=2) +## non-interactive use, multipage pdf +## ggsave("multipage.pdf", ml) +## interactive use; calling `dev.new` multiple times +ml +``` + + + diff -Nru r-cran-gridextra-0.9-1/vignettes/ngonGrob.rmd r-cran-gridextra-2.0.0/vignettes/ngonGrob.rmd --- r-cran-gridextra-0.9-1/vignettes/ngonGrob.rmd 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/vignettes/ngonGrob.rmd 2015-07-13 09:15:57.000000000 +0000 @@ -0,0 +1,62 @@ +--- +title: "Regular polygons and ellipses in grid graphics" +author: "Baptiste Auguie" +date: '`r Sys.Date()`' +vignette: > + %\VignetteEngine{knitr::rmarkdown} + %\VignetteIndexEntry{ngonGrob: regular polygons and ellipses in grid graphics} +output: + knitr:::html_vignette: + toc: yes +--- + +```{r setup, echo=FALSE, results='hide'} +library(knitr) +opts_chunk$set(message=FALSE, fig.width=4, fig.height=3) +``` + +The `gridExtra` package provides a basic implementation of regular polygons, `ngonGrob()/grid.ngon`, and a convenience function to draw ellipses, `ellipseGrob()/grid.ellipse()`. We illustrate below the basic usage of these vectorised functions. + +## Basic usage + +```{r basic} +library(gridExtra) +library(grid) +library(grid) +N <- 5 +xy <- polygon_regular(N)*2 + +# draw multiple polygons +g <- ngonGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), + unit(xy[,2],"cm") + unit(0.5,"npc"), + n=seq_len(N)+2, gp=gpar(fill=1:N)) + +grid.newpage() +grid.draw(g) +``` + +## Rotated and stretched polygons + +```{r rotated} +g2 <- ngonGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), + unit(xy[,2],"cm") + unit(0.5,"npc"), + n=seq_len(N)+2, rho=seq_len(N), + phase=0, angle=pi/(seq_len(N)+2), + size=1:N+5, gp=gpar(fill=1:N)) + +grid.newpage() +grid.draw(g2) +``` + +## Ellipses + +```{r ellipse} +g3 <- ellipseGrob(unit(xy[,1],"cm") + unit(0.5,"npc"), + unit(xy[,2],"cm") + unit(0.5,"npc"), + angle=-2*seq(0,N-1)*pi/N+pi/2, + size=5, rho=1/3, gp=gpar(fill=1:N)) + +grid.newpage() +grid.draw(g3) +``` + diff -Nru r-cran-gridextra-0.9-1/vignettes/tableGrob.rmd r-cran-gridextra-2.0.0/vignettes/tableGrob.rmd --- r-cran-gridextra-0.9-1/vignettes/tableGrob.rmd 1970-01-01 00:00:00.000000000 +0000 +++ r-cran-gridextra-2.0.0/vignettes/tableGrob.rmd 2015-07-13 21:53:10.000000000 +0000 @@ -0,0 +1,168 @@ +--- +title: "Displaying tables as grid graphics" +author: "Baptiste Auguie" +date: '`r Sys.Date()`' +vignette: > + %\VignetteEngine{knitr::rmarkdown} + %\VignetteIndexEntry{tableGrob: displaying tables as grid graphics} +output: + knitr:::html_vignette: + toc: yes +--- + +```{r setup, echo=FALSE, results='hide'} +library(knitr) +opts_chunk$set(message=FALSE, fig.width=4, fig.height=2) +``` + +Tabular data is usually formatted outside the graphics device, e.g via LaTeX, or html tables. However, in some cases it may be convenient to display *small* tables alongside graphics. A couple of packages offer this possibility with base graphics (`plotrix` for instance); the `gridExtra` provides the pair of `tableGrob/grid.table` functions for this purpose. + +## Basic usage + +```{r basic} +library(gridExtra) +library(grid) +d <- head(iris[,1:3]) +grid.table(d) +``` + +## Spacing + +The spacing of each row/column is automatic, and will adjust to bigger cell contents. Plotmath notation may be used, with the `parse=TRUE` argument. Note that this is applied to individual strings of text, and reverts to standard text if parsing fails (this is useful when mixing multiline text with plotmath in different cells). + +```{r annotations, fig.height=3} +d[2,3] <- "this is very wwwwwide" +d[1,2] <- "this\nis\ntall" +colnames(d) <- c("alpha*integral(xdx,a,infinity)", + "this text\nis high", 'alpha/beta') + +tt <- ttheme_default(colhead=list(fg_params = list(parse=TRUE))) +grid.table(d, theme=tt) + +``` + +## Aesthetic formatting + +The formatting is controlled by *themes*, which are nested lists of graphical parameters. See `ttheme_default` and `ttheme_minimal` for two built-in examples. Changing a few parameters at a time amounts to modifying the list with the new values. + +```{r theme, fig.width=8} +tt1 <- ttheme_default() +tt2 <- ttheme_minimal() +tt3 <- ttheme_minimal( + core=list(bg_params = list(fill = blues9, col=NA), + fg_params=list(fontface=3)), + colhead=list(fg_params=list(col="navyblue")), + rowhead=list(fg_params=list(col="navyblue", fontface=2L))) + +grid.arrange( + tableGrob(iris[1:4, 1:2], theme=tt1), + tableGrob(iris[1:4, 1:2], theme=tt2), + tableGrob(iris[1:4, 1:2], theme=tt3), + nrow=1) +``` + +## Text justification + +The text labels can be justified; the default is "centre" for the core, header, and row names. These settings can be adjusted by passing the relevant parameters of `textGrob` via the theme nested lists, + +```{r justify, fig.width=8} +tt1 <- ttheme_default() +tt2 <- ttheme_default(core=list(fg_params=list(hjust=1, x=0.9)), + rowhead=list(fg_params=list(hjust=1, x=0.95))) +tt3 <- ttheme_default(core=list(fg_params=list(hjust=0, x=0.1)), + rowhead=list(fg_params=list(hjust=0, x=0))) +grid.arrange( + tableGrob(mtcars[1:4, 1:2], theme=tt1), + tableGrob(mtcars[1:4, 1:2], theme=tt2), + tableGrob(mtcars[1:4, 1:2], theme=tt3), + nrow=1) +``` + +## Further gtable processing and integration + +Being based on `gtable`, the table can be further processed. In particular, we may edit the cell sizes to align with other content on the page. + +```{r sizes, fig.width=8} +g <- g2 <- tableGrob(iris[1:4, 1:3], cols = NULL, rows=NULL) +g2$widths <- unit(rep(1/ncol(g2), ncol(g2)), "npc") +grid.arrange(rectGrob(), rectGrob(), nrow=1) +grid.arrange(g, g2, nrow=1, newpage = FALSE) +``` + +Other grobs such as separating lines may be added. + +```{r separators} +g <- tableGrob(iris[1:4, 1:3], theme=ttheme_minimal()) +separators <- replicate(ncol(g) - 2, + segmentsGrob(x1 = unit(0,"npc")), + simplify=FALSE) +g <- gtable::gtable_add_grob(g, grobs = separators, + t = 1, b = nrow(g), l = seq_len(ncol(g)-2)+2) +grid.draw(g) +``` + +We may also access and modify individual cells, e.g. to highlight a value. + +```{r highlight} +g <- tableGrob(iris[1:4, 1:3]) +find_cell <- function(table, row, col, name="core-fg"){ + l <- table$layout + which(l$t==row & l$l==col & l$name==name) +} + +ind <- find_cell(g, 3, 2, "core-fg") +ind2 <- find_cell(g, 2, 3, "core-bg") +g$grobs[ind][[1]][["gp"]] <- gpar(fontsize=15, fontface="bold") +g$grobs[ind2][[1]][["gp"]] <- gpar(fill="darkolivegreen1", col = "darkolivegreen4", lwd=5) +grid.draw(g) +``` + +## Faster tables: an alternative grid function + +The `tableGrob` function can be very slow; unfortunately this is the price to pay for its versatility and easier implementation. We use individual `textGrob` and `rectGrob` elements for each cell, instead of relying on the vectorised implementation of these functions. The reason is practical: it is much easier to place, measure, and customise individual grobs, than modify the graphical parameters and positions of a single vectorised grob. An alternative function is presented below, using this vectorised approach, but lacking many of the customisations of `tableGrob`. + + +```{r ftable, fig.width=6} +grid.ftable <- function(d, padding = unit(4, "mm"), ...) { + + nc <- ncol(d) + nr <- nrow(d) + + ## character table with added row and column names + extended_matrix <- cbind(c("", rownames(d)), + rbind(colnames(d), + as.matrix(d))) + + ## string width and height + w <- apply(extended_matrix, 2, strwidth, "inch") + h <- apply(extended_matrix, 2, strheight, "inch") + + widths <- apply(w, 2, max) + heights <- apply(h, 1, max) + + padding <- convertUnit(padding, unitTo = "in", valueOnly = TRUE) + + x <- cumsum(widths + padding) - 0.5 * padding + y <- cumsum(heights + padding) - padding + + rg <- rectGrob(x = unit(x - widths/2, "in"), + y = unit(1, "npc") - unit(rep(y, each = nc + 1), "in"), + width = unit(widths + padding, "in"), + height = unit(heights + padding, "in")) + + tg <- textGrob(c(t(extended_matrix)), x = unit(x - widths/2, "in"), + y = unit(1, "npc") - unit(rep(y, each = nc + 1), "in"), + just = "center") + + g <- gTree(children = gList(rg, tg), ..., + x = x, y = y, widths = widths, heights = heights) + + grid.draw(g) + invisible(g) +} + +grid.newpage() +grid.ftable(head(iris, 4), gp = gpar(fill = rep(c("grey90", "grey95"), each = 6))) +``` + +