gridextra

ggplot2: Define plot layout with grid.arrange() as argument of do.call()

岁酱吖の 提交于 2019-11-29 01:12:18
问题 I want to obtained an unbalanced grid of plots such as require(ggplot2) require(gridExtra) df <- data.frame(value1 = rnorm(200), value2 = rnorm(200), value3 = rnorm(200), value4 = rnorm(200)) p1 <- ggplot(df) + geom_density(aes(x=value1)) p2 <- ggplot(df) + geom_density(aes(x=value2)) p3 <- ggplot(df) + geom_density(aes(x=value3)) p4 <- ggplot(df) + geom_density(aes(x=value4)) grid.arrange(p1, arrangeGrob(p2,p3,p4, ncol=3), heights=c(2.5/4, 1.5/4), ncol=1) but using a function myplot <-

changing title in multiplot ggplot2 using grid.arrange

不想你离开。 提交于 2019-11-28 21:28:05
问题 I have managed to make a 2x2 plot using grid.arrange: library(gridExtra) grid.arrange(p1,p3,p2,p4, ncol=2, nrow=2, top = "Daily QC: Blue") The main title of this multiplot is very small. Is there a way to change the title text size and font. 回答1: main=textGrob("Daily QC: Blue",gp=gpar(fontsize=20,font=3)) Edit with v>=2.0.0 of gridExtra, main has become top (for consistency with bottom , left and right ). 回答2: Due to changes in both packages grid and gridExtra , the current answer is outdated

Align edges of ggplot choropleth (legend title varies)

寵の児 提交于 2019-11-28 20:50:33
I am attempting to align the left and right edges of 4 ggplot choropleth maps using this method . I am unable to do this though. Original plot: library(ggplot2); library(gridExtra) crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests) states_map <- map_data("state") plot1 <- ggplot(crimes, aes(map_id = state)) + geom_map(aes(fill = Murder), map = states_map) + expand_limits(x = states_map$long, y = states_map$lat) + scale_fill_gradient(low="white", high="darkgreen", name="Really Long Name 1") plot2 <- plot1 + scale_fill_gradient(name="Really Long Name 2 and then some") plot3 <-

Arranging GGally plots with gridExtra?

末鹿安然 提交于 2019-11-28 14:02:03
I'd like to arrange my ggpairs plots with arrangeGrob : library(GGally) library(gridExtra) df <- structure(list(var1 = 1:5, var2 = 4:8, var3 = 6:10), .Names = c("var1", "var2", "var3"), row.names = c(NA, -5L), class = "data.frame") p1 <- ggpairs(df, 1:3) p2 <- ggpairs(df, 1:2) p <- arrangeGrob(p1, p2, ncol=2) which results in this error: Error in arrangeGrob(p1, p2, ncol = 2) : input must be grobs! Is there a way to work around this problem? tonytonov Unfortunately, I cannot see how that is possible. First, it's not going to work with gridExtra , since arrangeGrob operates on TableGrob objects

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

流过昼夜 提交于 2019-11-28 12:07:18
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 I'd suggest the following strategy: create the tableGrob, query its heights, split the rows to fit each page, library(gridExtra) library(grid) d <- iris[sample(nrow(iris), 187, TRUE),] tg <- tableGrob

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

做~自己de王妃 提交于 2019-11-28 11:44:25
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 <- viewport(x = 0.5, y = unit(1,"npc") - 0.52 * grobHeight(tg[[1]])) tg[[2]]$vp <- viewport(x = 0.5, y

reduce space between grid.arrange plots

若如初见. 提交于 2019-11-28 10:00:38
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 thinking or use of the package if I'm not using it in the way it was intended.) Good code bad space

Global legend using grid.arrange (gridExtra) and lattice based plots

家住魔仙堡 提交于 2019-11-28 01:49:34
问题 I am producing four plots using xyplot (lattice) and further combine them with grid.arrange (gridExtra). I would like to obtain a graph with a common global legend. The closest that I have reached is the following. They have to be in a matrix layout, otherwise an option would be to put them in a column and include only a legend for the top or bottom one. # Load packages require(lattice) require(gridExtra) # Generate some values x1<-rnorm(100,10,4) x2<-rnorm(100,10,4) x3<-rnorm(100,10,4) x4<

gridExtra Colour different rows with tableGrob

让人想犯罪 __ 提交于 2019-11-27 23:54:13
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 but I can't figure out how to apply that to my question. I believe the person who posted this question

Change text color for cells using TableGrob

我与影子孤独终老i 提交于 2019-11-27 22:26:10
Is there a way to individually change the color of the text of a cell when using tableGrob and ggplot2? For instance in the code below it'd be great if the cell with 1 could be blue and the cell with 2 could be red, with 3:8 all black. library(ggplot2) library(grid) mytable = as.table(matrix(c("1","2","3","4","5","6","7","8"),ncol=2,byrow=TRUE)) mytable = tableGrob(mytable,gpar.coretext = gpar(col = "black", cex = 1)) mydf = data.frame(x = 1:10,y = 1:10) ggplot( mydf, aes(x, y)) + annotation_custom(mytable) Much to my disappointment, this does not seem to be easy. The tableGrob function calls