gridextra

Is it possible to crop a plot when doing arrangeGrob?

青春壹個敷衍的年華 提交于 2019-12-06 05:38:10
I have a use-case similar to the following where I create multiple plots and arrange them into some page layout using gridExtra to finally save it as a PDF with ggsave : p1 <- generate_ggplot1(...) p2 <- generate_ggplot2(...) final <- gridExtra::arrangeGrob(p1, p2, ...) ggplot2::ggsave(filename=output.file,plot=final, ...) Is it possible to have plot p2 cropped while arranging it into the page layout with arrangeGrob ? The problem is that p2 has a lot of extra space on the top and bottom of it that I'd like to get rid of and since cropping doesn't seem viable using ggplot2 only I was thinking

Add annotation box to grid of ggplot objects

◇◆丶佛笑我妖孽 提交于 2019-12-06 03:34:30
问题 I am preparing a grid of 37 ggplot s using the grid.arrange function. To save space currently taken by the axis labels and to add some information like Sys.time() I would add a box to the lower right of the graphics grid. A minimal example using the mtcars data can be found below. The real data will cover very different ranges on x axis to facetting is not an option. Is there a way to add a "textbox" as shown in the *.pdf below within R to add further info using e.g. cat or print ? Any hint

How to draw a box/border around plots arranged side by side using grid.arrange in R

拥有回忆 提交于 2019-12-06 00:26:57
I have created two plots using ggplot as follows: library(ggplot2) library(gridExtra) g1 <- ggplot(iris, aes(Sepal.Width, Sepal.Length)) + geom_point() g2 <- ggplot(iris, aes(Petal.Width, Petal.Length)) + geom_point() grid.arrange(g1, g2, ncol=2) I would like to draw a border/box around the two side by side plots produced by grid.arrange...I think it is something to do with using grid.border, but am not sure of how exactly to do so. Will appreciate any help? Using an example from the ggplot help page: gg <- df <- data.frame(gp = factor(rep(letters[1:3], each = 10)), y = rnorm(30)) library(plyr

Saving plots using grid_draw method instead of gridExtra

▼魔方 西西 提交于 2019-12-05 20:32:33
I have used gridExtra to create 2 plots next to each other and I can save the object using ggsave However, the plots are misaligned in gridExtra so I used this method #Method 2 - gtable require(gtable) #Extract Grobs g1<-ggplotGrob(left) g2<-ggplotGrob(right) #Bind the tables g<-gtable:::cbind_gtable(g1, g2, "first") #Remove a row between the plots g <- gtable_add_cols(g, unit(-1,"cm"), pos=ncol(g1)) #draw grid.newpage() grid.draw(g) this method is covered in this link The perils of aligning plots in ggplot It worked beautifully for my graphs but when I save the object <- grid.draw(g) the

how do I get rid of random background grid from arrangeGrob

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 18:50:10
I need to wrap several plots in a grid, often an uneven number, so there'll often be an "empty spot" . I need to use arrangeGrob() -- not grid.arrange() -- because I want to save the plot for later, not plot() it right away. This works fine, but oddly, arrangeGrob() leaves some weird background in the empty spots. Like so: library(ggplot2) p1 <- ggplot(mtcars, aes(x=factor(cyl), y=mpg)) + geom_boxplot() p2 <- ggplot(mtcars, aes(x=factor(cyl), y=wt)) + geom_boxplot() p3 <- ggplot(mtcars, aes(x =factor(cyl), y=disp)) + geom_boxplot() library(gridExtra) y <- arrangeGrob(p1, p2, p3, ncol = 2) plot

ggplot2 : printing multiple plots in one page with a loop

帅比萌擦擦* 提交于 2019-12-05 13:44:55
I have several subjects for which I need to generate a plot, as I have many subjects I'd like to have several plots in one page rather than one figure for subject. Here it is what I have done so far: Read txt file with subjects name subjs <- scan ("ListSubjs.txt", what = "") Create a list to hold plot objects pltList <- list() for(s in 1:length(subjs)) { setwd(file.path("C:/Users/", subjs[[s]])) #load subj directory ifile=paste("Co","data.txt",sep="",collapse=NULL) #Read subj file dat = read.table(ifile) dat <- unlist(dat, use.names = FALSE) #make dat usable for ggplot2 df <- data.frame(dat)

Exact Positioning of multiple plots in ggplot2 with grid.arrange

风流意气都作罢 提交于 2019-12-05 07:43:21
I'm trying to create a multiple plot with the same x-axis but different y-axes, because I have values for two groups with different ranges. As I want to control the values of the axes (respectively the y-axes shall reach from 2.000.000 to 4.000.000 and from 250.000 to 500.000), I don't get along with facet_grid with scales = "free" . So what I've tried is to create two plots (named "plots.treat" and "plot.control") and combine them with grid.arrange and arrangeGrob . My problem is, that I don't know how to control the exact position of the two plots, so that both y-axes are positioned on one

How to put a wordcloud in a grob?

∥☆過路亽.° 提交于 2019-12-04 16:47:53
I've created a simple wordcloud: require(wordcloud) words <- c('affectionate', 'ambitious', 'anxious', 'articulate', 'artistic', 'caring', 'contented', 'creative', 'cynical', 'daring', 'dependable', 'easygoing', 'energetic', 'funny', 'generous', 'genuine', 'goodlistener', 'goodtalker', 'happy', 'hardworking', 'humerous', 'impulsive', 'intelligent', 'kind', 'loyal', 'modest', 'optimistic', 'outgoing', 'outrageous', 'passionate', 'perceptive', 'physicallyfit', 'quiet', 'rational', 'respectful', 'romantic', 'shy', 'spiritual', 'spontaneous', 'sweet', 'thoughtful', 'warm') freqs <- c(134, 53, 0, 5

plotting a list of grobs

你。 提交于 2019-12-04 13:06:51
DISCLOSURE: I'm not sure how to make a reproducible example for this question. I'm trying to plot a list of grobs using the gridExtra package. I have some code that looks like this: ## Make Graphic Objects for Spec and raw traces for (i in 1:length(morletPlots)){ gridplots_Spec[[i]]=ggplotGrob(morletPlots[[i]]) gridplots_Raw[[i]]=ggplotGrob(rawPlot[[i]]) gridplots_Raw[[i]]$widths=gridplots_Spec[[i]]$widths } names(gridplots_Spec)=names(morletPlots) names(gridplots_Raw)=names(rawPlot) ## Combine spec and Raw traces g=list() for (i in 1:length(rawPlot)){ g[[i]]=arrangeGrob(gridplots_Spec[i]

R - how to allocate screen space to complex ggplot images

狂风中的少年 提交于 2019-12-04 10:30:07
问题 I am trying to write a script that produces four different plots in a single image. Specifically, I want to recreate this graphic as closely as possible: My current script produces four plots similar to these but I cannot figure out how to allocate screen real-estate accordingly. I want to: modify the height and width of the plots so that all four have uniform width, one is substantially taller than the others which have uniform height among them define the position of the legends by