r - Make a matrix of plots with row and column titles -
r - Make a matrix of plots with row and column titles -
using par(mfrow = c(m,n))
command can create matrix of plots m
rows , n
columns.
in special cases, there pattern in plots, such plots in each column share of import attribute, , plots in each row share different of import attribute. such info can included in title of each of m*n
plots individually, repetitive.
is there convenient way append column names (only above top row of plots) , row names (only left of left column of plots) in such grid?
best solution far: utilize text()
command place text outside of left-and-top plots. pretty unsatisfactory, requires many separate commands, , tweaking arguments such srt = 90
create text vertical on left margin, , using xpd = na
within of par()
.
the lattice , ggplot2 packages have tools creating multiple plots in grid. may speed entire process if apply want do.
library(lattice) splom( ~ iris[,1:4], data=iris, groups=species ) xyplot( mpg ~ wt | factor(cyl)*factor(am), data=mtcars ) library(ggplot2) p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() p + facet_grid(am ~ cyl)
using base of operations graphics can start setting outer margin, see oma
argument par
command, utilize mtext
function write text outer margin labels.
par( oma=c(0,6,6,0), mfrow=c(2,2), mar=c(2,2,1,1)+0.1 ) with(iris, plot(sepal.width, petal.width, ann=false)) mtext( 'width', side=3, line=2, at=grconvertx(0.5,'npc','nic'), outer=true ) mtext( 'width', side=2, line=2, at=grconverty(0.5,'npc','nic'), outer=true ) mtext( 'sepal', side=3, line=4, outer=true, cex=2 ) mtext( 'petal', side=2, line=4, outer=true, cex=2 ) with(iris, plot(sepal.length, petal.width, ann=false)) mtext( 'length', side=3, line=2, at=grconvertx(0.5,'npc','nic'), outer=true ) with(iris, plot(sepal.width, petal.length, ann=false)) mtext( 'length', side=2, line=2, at=grconverty(0.5, 'npc','nic'), outer=true ) with(iris, plot(sepal.length, petal.length, ann=false))
r plot
Comments
Post a Comment