gridextra

Exact Positioning of multiple plots in ggplot2 with grid.arrange

扶醉桌前 提交于 2019-12-22 05:19:07
问题 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

grid.arrange from gridExtras exiting with “only 'grobs' allowed in 'gList'” after update

百般思念 提交于 2019-12-21 06:47:03
问题 I just updated R, R Studio, and a bunch of packages including ggplot2 and gridExtras on my Mac. Now gridExtras is failing in basic plotting with the error: "only 'grobs' allowed in "gList"" Here's some code that should work but does not: library(ggplot2) p1 = qplot(1:10,rnorm(10)) p2 = qplot(1:10,rnorm(10)) library(gridExtra) grid.arrange(p1, p2, ncol=2, main = "Main title") This dumps out the following error: Error in gList(list(grobs = list(list(x = 0.5, y = 0.5, width = 1, height = 1, :

Universal x axis label and legend at bottom using grid.arrange

本秂侑毒 提交于 2019-12-20 01:34:49
问题 I am trying to plot a number of graphs next to each other using grid.arrange. Specifically, I would like the plots to have a shared x axis label and a legend at the bottom. Here is the code I am using for the arrangement (working example here), sans the universal x axis: plot.c <- grid.arrange(arrangeGrob(plot.3 + theme(legend.position="none"), plot.2 + theme(legend.position="none"), plot.4 + theme(legend.position="none"), nrow=1), my.legend, main="Title goes here", left=textGrob("Y Axis",

gridExtra 2.0.0 change title size

馋奶兔 提交于 2019-12-18 14:47:13
问题 I know that gridExtra has been updated. As a result, I'm left wondering how to change title sizes. This no longer works grid.arrange(a, b, c, d,ncol=2, nrow=2, main=textGrob("Title", gp=gpar(fontsize=15,font=8))) That no longer works, the option for main has been changed to top but I can't figure out the textGrob features to alter the font size). Any clues? Thanks 回答1: First, import the package grid with either library() or require() . Second, change main to top in your code. See below:

ggplot grobs align with tableGrob

孤者浪人 提交于 2019-12-18 06:58:27
问题 I'm having difficulty to find solution for aligning ggplot grob and table grob. I tried to follow the instruction here but still didn't give the results I wanted. library(grid) library(gridExtra) library(ggplot2) library(tibble) library(gtable) dat <- tibble::rownames_to_column(mtcars, "car") #convert rownames to first col plot1 <- ggplot(dat, aes(car, mpg)) + geom_bar(stat = "identity") + coord_flip() g1 <- ggplotGrob(plot1) tb1 <- tableGrob(dat$cyl) g1 <- gtable_add_cols(g1, unit(0.2, "npc"

Arranging GGally plots with gridExtra?

荒凉一梦 提交于 2019-12-17 20:54:52
问题 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? 回答1: Unfortunately, I cannot see how that is

Change text color for cells using TableGrob

橙三吉。 提交于 2019-12-17 16:21:38
问题 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

The perils of aligning plots in ggplot

喜你入骨 提交于 2019-12-17 10:49:11
问题 QUESTION How do you combine separate plots (ggplot2), with different y-axis and different plot heights, yet retain alignment? DETAIL When combining plots with grid.arrange (method1), with different y-axis units, they do not align. One way around this is to use gtable (method2), but I cannot adjust the relative height of the plots. EXAMPLE require(ggplot2) #Make two plots, with different y axis x = c(1, 5) y= c(.1, .4) data1<-data.frame(x,y) top<- ggplot(data1, aes(x=x, y=y))+ geom_line() x =

Remove page numbers from marrangeGrob (or arrangeList) pdf

眉间皱痕 提交于 2019-12-14 00:33:09
问题 marrangeGrob in the gridExtra arranges grobs (usually ggplots in my case) in rows, columns and pages. It also numbers the pages. require(ggplot2) require(plyr) require(gridExtra) p <- function(plotdata) { x <- ggplot(plotdata, aes(wt, mpg)) + geom_point() + ggtitle(plotdata$gear[1]) return(x) } all <- dlply(mtcars, .(gear), p) allarranged <- do.call(marrangeGrob, c(all, nrow=1, ncol=2)) ggsave("multipage.pdf", allarranged, width=12) That's a silly but reproducible example. Now inspect the

tableGrob: set the height and width of a grid.table

依然范特西╮ 提交于 2019-12-13 13:17:59
问题 I'm trying to make a function that will give me a plot ready for indesign, illustrator or inkscape. In trying to do so, I have 2 problems I cannot solve. 1) set the width and height of my plot (or just the grobTable): The output I get is very small and when upscaling it in illustrator the font follows and become way to big. Therefore I want to make plots with manually defined widths and heights. 2) Sometimes the title, note and rownames gets "misplaced" (see the difference between plot 1 and