gridextra

Multiple plots on one page using ggplot

倾然丶 夕夏残阳落幕 提交于 2019-12-01 20:54:17
I have 12 plots generated by a loop and I want to plot them with 3 rows and 2 columns on one page (2 pages in total). I know how to do it in R pdf("1.pdf") par(mfrow = c(3, 2)) for (i in 1:12) { x <- 1:10 y <- 2*x + rnorm(x) plot(x, y) } dev.off() But how to do this using ggplot ? library(ggplot2) library(grid) library(gridExtra) for (i in 1:12) { x <- 1:10 y <- 2*x + rnorm(x) qplot(x, y) } I think I have to use grid.arrange but need some help on that. Thanks. You might want to take a look at the cowplot package that allows more flexibility than just using a naked grid.arrange . This works -

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

我与影子孤独终老i 提交于 2019-12-01 18:52:57
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", rot = 90, vjust = 1), nrow=2,heights=c(10, 1)) The legend is a TableGrob object; the universal x axis

Multicolored title with R

柔情痞子 提交于 2019-12-01 17:06:23
I'd like to add colors to certain words in titles to my graphs. I've been able to find some precedent here . Specifically, I'd like the text that's wrapped in apostrophes (in the output, below) to correspond to the color of their respective bar charts. Here's how far I've gotten with titles in R before having to export a PDF to Adobe Illustrator or other program. name <- c("Peter", "Gabriel", "Rachel", "Bradley") age <- c(34, 13, 28, 0.9) fake_graph <- family[order(family$age, decreasing = F), ] fake_graph <- within(fake_graph, { bar_color = ifelse(fake_graph$name == "Rachel", "blue", "gray")

Multicolored title with R

放肆的年华 提交于 2019-12-01 16:22:37
问题 I'd like to add colors to certain words in titles to my graphs. I've been able to find some precedent here. Specifically, I'd like the text that's wrapped in apostrophes (in the output, below) to correspond to the color of their respective bar charts. Here's how far I've gotten with titles in R before having to export a PDF to Adobe Illustrator or other program. name <- c("Peter", "Gabriel", "Rachel", "Bradley") age <- c(34, 13, 28, 0.9) fake_graph <- family[order(family$age, decreasing = F),

Set the height of the graphs y-axis in grid.arrange, but not of the entire plot area

人盡茶涼 提交于 2019-12-01 15:50:10
问题 When using grid arrange I encountered the following problem : I want all my panels (a,b,c) to have the same size, but as I have removed the labels and tickmarks from panel a and b (to have only a single x-axis) the size of the graphs a and b is bigger and equals the size of graph c + space for the lable and tick-marks of c. I cannot make use of ggplot2::facet_grid either, since I want to specify the y-axis limits independently (eg. of a until 40 and of b and c until 15). Below you can find

R grid.table column heading character rotation

扶醉桌前 提交于 2019-12-01 13:23:50
I am attempting to use grid.table to produce an image of a table for placement in a word document using Rstudio-knitr-pandoc. It is rather large with long column names. The solution I would like to accomplish is rotating the column headings to 90 vertical. Is this possible with grid.table or any other means? I have tried toxinsGrob<-tableGrob(cyano.x.t,name='toxins',edits=gEdit(gPath='gpar.coltext',rot=90)) grid.draw(toxinsGrob) to no avail. Suggetions? Joel it's easy with the new version of grid.table, tt = ttheme_default(colhead=list(fg_params=list(rot=90))) grid.newpage() grid.table(head

Combining grid.table and base package plots in R figure

不羁的心 提交于 2019-12-01 11:31:57
I am trying to combine tables from grid.table together with plots from base package into a single plot. As far as I understand, grid.table produced the same type of output as the one produced by ggplot. So the problem is similar to the one in this thread: Combine base and ggplot graphics in R figure window I tried to apply the solution from that thread, but it does not work for me. The first table is placed in the correct position, but the second is not. The solution from that thread works if I have no more than 1 table produced by grid.table. What are the modifications I have to do, to make

Combining grid.table and base package plots in R figure

会有一股神秘感。 提交于 2019-12-01 09:40:11
问题 I am trying to combine tables from grid.table together with plots from base package into a single plot. As far as I understand, grid.table produced the same type of output as the one produced by ggplot. So the problem is similar to the one in this thread: Combine base and ggplot graphics in R figure window I tried to apply the solution from that thread, but it does not work for me. The first table is placed in the correct position, but the second is not. The solution from that thread works if

How can I align multiple plots by their titles instead of plot area?

╄→尐↘猪︶ㄣ 提交于 2019-12-01 07:19:58
问题 I'm using egg to align multiple plots on a page. I'm wondering if it's possible to align two columns by the titles a) and c) instead of plot area? Thanks! Code: library(egg) library(grid) p1 <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point() + ggtitle("a)") p1 p2 <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point() + facet_wrap(~ cyl, ncol = 2, scales = "free") + guides(colour = "none") + theme() + ggtitle("b)") p2 p3 <- ggplot(mtcars, aes(mpg, wt, colour =

Margins between plots in grid.arrange

拟墨画扇 提交于 2019-12-01 00:24:28
问题 I dont seem to be able to find a solution as to how to increase the space between two plots with grid.arrange. I find no clue as to how to proceed. I dont want to change the size of the plots or anything like that. grid.arrange(plot1, plot2, ncol=2) (The stuff below was added later): This is the code that I have: x11() cs <- grid.arrange(arrangeGrob(b, a, ncol=2, top = textGrob( "B", vjust = 0.5, hjust = 19.5, gp = gpar( fontface = "bold", cex = 1.5)), left = textGrob(~ Delta * "SCR (p - d)"