Arrange base plots and grid.tables on the same page
To combine base
plots and grid
objects the package gridBase
is useful.
A rough worked example base on your layout above
library(grid)
library(gridBase)
library(gridExtra)
layout(matrix(c(1,3, 2,3, 4,3), nrow = 3, ncol = 2, byrow = TRUE))
# First base plot
plot(1:10)
# second base plot
frame()
# Grid regions of current base plot (ie from frame)
vps <- baseViewports()
pushViewport(vps$inner, vps$figure, vps$plot)
# Table grob
grob <- tableGrob(iris[1:2,1:2])
grid.draw(grob)
popViewport(3)
# third base plot
plot(1:10)
# fourth
frame()
vps <- baseViewports()
pushViewport(vps$inner, vps$figure, vps$plot)
grid.draw(grob)
popViewport(3)
Which gives
Arrange multiple plots into one grid
Since you are not using grid based graphics system, you can use par()
to arrange your figures.
See if this works:
a <- c(0.1,0.5,1,2,5,10,100)
b <- c(0.1,0.5,1,2,5,10,100)
par(mfrow=c(7,7), mar=c(2,2,2,0))
for(m in 1:7)
{
...
Adding a small table to a base graphics multiple plot chart
With plotrix you can modify your code as follows:
library(plotrix)
Table1<- data.frame( a=1:6,b=2:7,c=3:8)
layout(matrix(c(1:4), 2, 2, byrow = FALSE), widths=c(1,1), heights=c(1,1))
plot(1:6)
plot(2:7)
plot(3:8)
plot.new()
addtable2plot(0,0,Table1,
xpad=6, ypad=2,
bty='o',
display.rownames = TRUE,
hlines = TRUE,
vlines = TRUE,
title = "The table")
Output Plot and Table to Same Page for Each Group
since you want the tableGrob to be outside the plot panel and not inside, you shouldn't use annotation_custom, but arrangeGrob to arrange a plot and a table on a page. The list of grobs can then be printed page by page in the pdf device.
library(plyr)
plots <- dlply(iris, "Species", function(d) {
arrangeGrob(qplot(1,1), tableGrob(head(d)))
})
pdf("multipage.pdf")
plots
dev.off()
R grid.table - table keeps plotting on top of other plots
You can use grid.newpage() to get a new page in your panel.
library(grid)
d <- head(iris[,1:3])
plot(d)
library(gridExtra)
grid.newpage()
grid.table(d)
multiple different sized plots in same window in R?
EDIT -- fixed to shrink third chart per OP.
library(patchwork)
design <- c( # we specify the top, left, bottom, and right
area(1, 1, 4, 4), # coordinates for each of the three plots
area(1, 5, 2, 6),
area(3, 5)
)
allPlots[[1]] + allPlots[[2]] + allPlots[[3]] +
plot_layout(design = design)
Related Topics
Use Merge() to Update a Data Frame with Values from a Second Data Frame
How to Make Tibbles Display Significant Digits
Update Subset of Data.Table Based on Join
Pasting Elements of Two Vectors Alphabetically
What Are the R Sorting Rules of Character Vectors
Return Index from a Vector of the Value Closest to a Given Element
Remove Backslashes from Character String
How to Obtain an 'Unbalanced' Grid of Ggplots
How to Make R Beep/Play a Sound at the End of a Script
How to Spread Columns with Duplicate Identifiers
Fast Pairwise Simple Linear Regression Between Variables in a Data Frame
Efficiently Sum Across Multiple Columns in R
Avoid Ggplot Sorting the X-Axis While Plotting Geom_Bar()
Reading Multiple Files and Calculating Mean Based on User Input