我想在R中绘制40个不同的图。我如何控制图的高度和宽度,以便x和y轴可读?无论您将绘图视图中的图形高度缩小到小于您想要的大小,无论您设置的高度和宽度如何都会出现。
这是一个有26个地块的玩具示例。我在这里使用多绘图功能:http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/
PLOT_LIST= list()
c <-rep(letters[1:26], 1,each=26)
x = rep(1:26,26)
y = rep(1:26,26)
d<- data.frame(cbind(c,x,y))
head(d)
uniCat= as.character(unique(d[,1]))
uniCat
for (i in 1:length(uniCat)){
#i=1
temp= subset(d, c == uniCat[i] )
PLOT_LIST[[i]]<- ggplot(temp, aes(x=x, y=y),height = 200, width= =200) + geom_bar(stat="identity") + ggtitle( uniCat[i])
}
multiplot(plotlist=PLOT_LIST, cols= 4)
在这里你可以看到输出。轴是不可读的。如何修复高度和宽度以使其可消耗?高度= 200,宽度= 200似乎不起作用。
谢谢。
这是多重时间函数:
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
library(grid)
# Make a list from the ... arguments and plotlist
plots <- c(list(...), plotlist)
numPlots = length(plots)
# If layout is NULL, then use 'cols' to determine layout
if (is.null(layout)) {
# Make the panel
# ncol: Number of columns of plots
# nrow: Number of rows needed, calculated from # of cols
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
ncol = cols, nrow = ceiling(numPlots/cols))
}
if (numPlots==1) {
print(plots[[1]])
} else {
# Set up the page
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))
# Make each plot, in the correct location
for (i in 1:numPlots) {
# Get the i,j matrix positions of the regions that contain this subplot
matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))
print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
layout.pos.col = matchidx$col))
}
}
}