gridextra

force a regular plot object into a Grob for use in grid.arrange

China☆狼群 提交于 2019-11-27 06:50:07
问题 b <- ggplot(cars,aes(x=speed,y=dist))+geom_line() grid.arrange( b, plot(cars), ncol=1 ) gives me the following error Error in gList(list(grobs = list(list(x = 0.5, y = 0.5, width = 1, height = 1, : only 'grobs' allowed in "gList" Let's assume my second graph has to come out of the plot function. How would one convert that output to a grob -like object so it plays nicely with grid.arrange ? 回答1: you can try with gridGraphics library(gridGraphics) grab_grob <- function(){ grid.echo() grid.grab(

R: ggplot2 make two geom_tile plots have equal height

两盒软妹~` 提交于 2019-11-27 06:29:25
问题 I have two ggplot geom_tile plots that I put together using grid.arrange() from the gridExtra library. This is the result library(ggplot2) library(plyr) p3 <- ggplot2(...) p4 <- ggplot2(...) grid.arrange(p3, p4, ncol=2) I would like to get it so that the two plots have the same height and are aligned. I have fiddled around a bit with gtable to alter the dimensions directly but this doesn't seem to work out. gA <- ggplot_gtable(ggplot_build(p3)) gB <- ggplot_gtable(ggplot_build(p4)) maxHeight

Align grob at fixed top/center position, regardless of size

China☆狼群 提交于 2019-11-27 06:26:37
问题 I have some table grobs, some long and some short. I'd like to draw these at the top/center of the page (with a small margin). From this answer, I got a helpful starting point, but the positioning is dependent on each grob's height. library(gridExtra) # fake data my_df <- data.frame(col1=rep('hello', 35), col2=round(rnorm(35), 3)) # list of grobs tg <- list(tableGrob(my_df[1:30, ]), tableGrob(my_df[31:35, ])) # this positions grobs at center top, but varies based on rows in table tg[[1]]$vp <

print to pdf file using grid.table in r - too many rows to fit on one page

烈酒焚心 提交于 2019-11-27 05:56:22
问题 I'm trying to output a dataframe of about 40 rows and 5 columns to a .pdf file using grid.table in gridExtra package of R. However, 40 rows is too long for a page so the .pdf file only shows part of the dataframe. I want to know if I can print two columns on one page so all of the rows show up on one page. Alternatively, I need to know how to print the dataframe over multiple pages. Thanks, John 回答1: I'd suggest the following strategy: create the tableGrob, query its heights, split the rows

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

删除回忆录丶 提交于 2019-11-27 04:55:54
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", "Item 4 is even longer if you can believe it", "And there is a third item", "And a fourth item"), est=c(.3, .5,

Removing one tableGrob when applied to a box plot with a facet_wrap

谁都会走 提交于 2019-11-27 04:01:11
问题 I'm using the code below to enrich a box plot with a summary table for categorical variable created on the x-axis. # Libs require(ggplot2); require(gridExtra); require(grid); require(ggthemes) # Data data(mtcars) # Function to summarise the data fun_dta_sum <- function(var_sum, group, data) { sum_dta <- data.frame( aggregate(var_sum ~ group, FUN = min, data = data), aggregate(var_sum ~ group, FUN = max, data = data), aggregate(var_sum ~ group, FUN = mean, data = data)) sum_dta <- sum_dta[,c(1

reduce space between grid.arrange plots

心不动则不痛 提交于 2019-11-27 03:26:27
问题 I asked a question HERE about grid arrange and got a terrific response. I want to reduce the space between plots now but get an error. First I present the code that works and then the error code (what I tried). I can't actually find grid.arrange and have always assumed it comes from gridExtra but I may be incorrect. so 2 parts: How can I reduce space between plots with grid arrange Where can I find documentation about grid.arrange (Baptiste I know you maintain gridExtra so please correct my

How to plot barchart onto ggplot2 map [duplicate]

╄→гoц情女王★ 提交于 2019-11-27 03:20:31
问题 This question already has an answer here : Plotting bar charts on map using ggplot2? (1 answer) Closed 2 years ago . I have found similar answers to questions like this one, but most of them are using packages rworldmap , ggmap , ggsubplot or geom_subplot2d . See for example here or here. I'd like to know how I can plot other ggplot-objects such as a bar-chart onto a map, that is created from a shapefile. The one I'm using can be downloaded here. EDIT As @beetroot correctly pointed out, the

gridExtra Colour different rows with tableGrob

◇◆丶佛笑我妖孽 提交于 2019-11-26 23:23:17
问题 I have a question regarding tableGrob/grid.table from the gridExtra package. Using the regular parameter settings, it is straightforward to colour alternate rows. However, I was hoping that it might be feasible to get a bit more control over the colouring of the rows. For example, is it possible to colour every third row in a different colour? I suspect the grid.edit function is one way to approach this, judging by the example in this link: http://code.google.com/p/gridextra/wiki/tableGrob

store arrangeGrob to object, does not create printable object

血红的双手。 提交于 2019-11-26 21:35:27
问题 I want to save , but not print (for now), a bunch of ggplot() s into a grid (via arrangeGrob() , correct?), then print and retrieve them later. This is a reboot of an existing question. Strangely, that answer does not work, and I have no idea why. I am using the exact same code. library(ggplot2) p1 <- ggplot(mtcars, aes(x=factor(cyl), y=mpg)) + geom_boxplot() p2 <- ggplot(mtcars, aes(x=factor(cyl), y=wt)) + geom_boxplot() library(gridExtra) y <- arrangeGrob(p1, p2) class(y) y Strangely, that