library(grid)
titles <- c(
"Edgar Anderson's Iris Data",
paste(
"This famous (Fisher's or Anderson's) iris data set gives the measurements",
"in centimeters of the variables sepal length and width and petal length",
"and width, respectively, for 50 flowers from each of 3 species of iris."
)
)
footnotes <- c(
"The species are Iris setosa, versicolor, and virginica.",
paste(
"iris is a data frame with 150 cases (rows) and 5 variables (columns) named",
"Sepal.Length, Sepal.Width, Petal.Length, Petal.Width, and Species."
)
)
## empty plot
grid.newpage()
grid.draw(
decorate_grob(
NULL,
titles = titles,
footnotes = footnotes,
page = "Page 4 of 10"
)
)
# grid
p <- gTree(
children = gList(
rectGrob(),
xaxisGrob(),
yaxisGrob(),
textGrob("Sepal.Length", y = unit(-4, "lines")),
textGrob("Petal.Length", x = unit(-3.5, "lines"), rot = 90),
pointsGrob(iris$Sepal.Length, iris$Petal.Length, gp = gpar(col = iris$Species), pch = 16)
),
vp = vpStack(plotViewport(), dataViewport(xData = iris$Sepal.Length, yData = iris$Petal.Length))
)
grid.newpage()
grid.draw(p)
grid.newpage()
grid.draw(
decorate_grob(
grob = p,
titles = titles,
footnotes = footnotes,
page = "Page 6 of 129"
)
)
## with ggplot2
library(ggplot2)
p_gg <- ggplot2::ggplot(iris, aes(Sepal.Length, Sepal.Width, col = Species)) +
ggplot2::geom_point()
p_gg
p <- ggplotGrob(p_gg)
grid.newpage()
grid.draw(
decorate_grob(
grob = p,
titles = titles,
footnotes = footnotes,
page = "Page 6 of 129"
)
)
## with lattice
library(lattice)
xyplot(Sepal.Length ~ Petal.Length, data = iris, col = iris$Species)
p <- grid.grab()
grid.newpage()
grid.draw(
decorate_grob(
grob = p,
titles = titles,
footnotes = footnotes,
page = "Page 6 of 129"
)
)
# with gridExtra - no borders
library(gridExtra)
grid.newpage()
grid.draw(
decorate_grob(
tableGrob(
head(mtcars)
),
titles = "title",
footnotes = "footnote",
border = FALSE
)
)
Run the code above in your browser using DataLab