gridextra

Specify widths and heights of plots with grid.arrange

房东的猫 提交于 2019-11-26 18:01:22
问题 I have three plots and I try to combine them with grid.arrange. The last plot should have a smaller height than the first two plots and all the plots should have the same width. A working example: p1 <- qplot(mpg, wt, data=mtcars) p2 <- p1 p3 <- p1 + theme(axis.text.y=element_blank(), axis.title.y=element_blank()) grid.arrange(arrangeGrob(p1,p2, ncol=1, nrow=2), arrangeGrob(p3, ncol=1, nrow=1), heights=c(4,1)) Here, the last plot has a larger width than the first two. In my real data, even if

How do I fit a very wide grid.table or tableGrob to fit on a pdf page?

前提是你 提交于 2019-11-26 17:52:03
问题 I have a fairly wide table (4/3 of page width) that I'm trying to print using grid.table or grid.arrange (via tableGrob) into a pdf file. The table goes beyond page boundaries and gets clipped. Is there a way to force grid.table/grid.arrange to scale the table to the print area? 回答1: There is a way, but it's unclear what should happen when the text is too wide to fit in some cells. One option is to set the widths manually, library(grid) library(gridExtra) g1 <- g2 <- tableGrob(head(iris, 10),

Saving grid.arrange() plot to file

六眼飞鱼酱① 提交于 2019-11-26 16:55:51
I am trying to plot multiple plots using ggplot2 , arranging them using grid.arrange() . Since I managed to find someone describing the exact problem I have, I have quoted from the problem description from link : When I use ggsave() after grid.arrange() , i.e. grid.arrange(sgcir1,sgcir2,sgcir3,ncol=2,nrow=2) ggsave("sgcirNIR.jpg") I do not save the grid plot but the last individual ggplot. Is there any way of actually saving the plot as displayed by grid.arrange() using ggsave() or something similar? Other than using the older way jpeg("sgcirNIR.jpg") grid.arrange(sgcir1,sgcir2,sgcir3,ncol=2

How to use empty space produced by facet_wrap?

安稳与你 提交于 2019-11-26 16:18:25
问题 I have a faceted plot that forms an n x m grid. By design, the last (bottom-right) cell is always empty, so I'd like to utilize the extra space by adding another ggplot object. My current solution relies on low-level viewport approach, which is not very elegant and requires some hard-coding for position and size. Instead, I assume the empty space is reachable in some other fashion, probably with gridExtra ? Here's a minimal example for n=m=2 . Note that the edges are not aligned properly, so

Multiple ggplots of different sizes

橙三吉。 提交于 2019-11-26 15:33:55
问题 It's relatively simple using grid.arrange in the gridExtra package to arrange multiple plots in a matrix, but how can you arrange plots (the ones I'm working on are from ggplot2 ) when some plots are intended to be larger than others? In base, I can use layout() such as in the example below: nf <- layout(matrix(c(1,1,1,2,3,1,1,1,4,5,6,7,8,9,9), byrow=TRUE, nrow=3)) layout.show(nf) what is the equivalent for ggplot plots? Some plots for inclusion library(ggplot2) p1 <- qplot(x=wt,y=mpg,geom=

Plot over multiple pages

守給你的承諾、 提交于 2019-11-26 14:17:47
问题 I have the facet_wrap function to make multiple graphs (n=~51) but they all appear on one page. Now after searching, I found out that ggplot2 can't place graphs on multiple pages. Is there a way to do this? I looked at this question (Multiple graphs over multiple pages using ggplot) and tried out the code, with little success. Here is my code for my graphs, it produces ~51 graphs on one page, making them very small and hard to see, if I could print this to 1 graph per page in a pdf, that

set ggplot plots to have same x-axis width and same space between dot plot rows

好久不见. 提交于 2019-11-26 11:25:38
问题 Updated question to incorporate a partial solution already answered on SO I am using ggplot2 to create several plots and gridExtra to combine the plots into one figure with several panels, all in one column. My problem is that I can\'t get the space between the dot plot rows to be consistent in both plots. library(ggplot2) # data dat1 <- data.frame(VARIABLES=c(\"Item 1\", \"Item 2 is a little longer\"), est=c(.3, .5), min=c(.2, .4), max=c(.4, .7)) dat2 <- data.frame(VARIABLES=c(\"Item 3\", \

Saving grid.arrange() plot to file

好久不见. 提交于 2019-11-26 04:59:04
问题 I am trying to plot multiple plots using ggplot2 , arranging them using grid.arrange() . Since I managed to find someone describing the exact problem I have, I have quoted from the problem description from link: When I use ggsave() after grid.arrange() , i.e. grid.arrange(sgcir1,sgcir2,sgcir3,ncol=2,nrow=2) ggsave(\"sgcirNIR.jpg\") I do not save the grid plot but the last individual ggplot. Is there any way of actually saving the plot as displayed by grid.arrange() using ggsave() or something

Add a common Legend for combined ggplots

梦想与她 提交于 2019-11-26 02:48:20
I have two ggplots which I align horizontally with grid.arrange . I have looked through a lot of forum posts, but everything I try seem to be commands that are now updated and named something else. My data looks like this; # Data plot 1 axis1 axis2 group1 -0.212201 0.358867 group2 -0.279756 -0.126194 group3 0.186860 -0.203273 group4 0.417117 -0.002592 group1 -0.212201 0.358867 group2 -0.279756 -0.126194 group3 0.186860 -0.203273 group4 0.186860 -0.203273 # Data plot 2 axis1 axis2 group1 0.211826 -0.306214 group2 -0.072626 0.104988 group3 -0.072626 0.104988 group4 -0.072626 0.104988 group1 0

Multiple plots in for loop ignoring par

隐身守侯 提交于 2019-11-26 02:02:55
问题 I am trying to generate 10 pairs of plots with a few pairs per page of plots, and am using a for loop to construct the pairs. However, the plots are sent to the device as separate plots instead of pages. The MWE below has identical constructions for base graphics and ggplot versions, but the base graphics works and ggplot does not. What do I need to do to get the pagination correct in the second version? library(ggplot2) attach(mtcars) # correct configuration par(mfrow=c(2,2)) for (ii in 1:3)