r-grid

How can I use grid to edit a ggplot2 object to add math expressions to facet labels?

空扰寡人 提交于 2019-11-27 02:24:56
问题 I need to put Greek letters into facet labels using facet_wrap() in ggplot2. I found a Link describing the same for facet_grid(). I applied this for my data, using the following code: levels(parameters) <- c(expression(alpha), expression(beta)) p + facet_grid(.~parameters, labeller = label_parsed) This works great and does exactly what I want. However, I need to use facet_wrap() instead (to get separate y-axes for both paramters, and also to plot even more parameters in different columns and

Specifying ggplot2 panel width

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 01:38:05
I have two ggplots on the same page, and I'd like their panels to be the same width. Some sample data: dfr1 <- data.frame( time = 1:10, value = runif(10) ) dfr2 <- data.frame( time = 1:10, value = runif(10, 1000, 1001) ) One plot below the other: p1 <- ggplot(dfr1, aes(time, value)) + geom_line() p2 <- ggplot(dfr2, aes(time, value)) + geom_line() grid.newpage() pushViewport(viewport(layout = grid.layout(2, 1))) print(p1, vp = viewport(layout.pos.row = 1, layout.pos.col = 1)) print(p2, vp = viewport(layout.pos.row = 2, layout.pos.col = 1)) How do I specify the panel widths and positions in each

How to apply cross-hatching to a polygon using the grid graphical system?

你说的曾经没有我的故事 提交于 2019-11-26 23:13:28
问题 Several functions in R's base graphical system, including rect() and polygon() , support cross-hatching via their angle= and density= arguments: x = c(0, 0.5, 1, 0.5) y = c(0.5, 1, 0.5, 0) par(mar=c(0,0,0,0)) plot.new() polygon(x, y, angle=45, density=10) How might I apply similar cross-hatching to a polygon drawn by the grid graphical system's grid.polygon() function: library(grid) grid.newpage() grid.polygon(x,y) I've looked in the documentation for ?grid.polygon and ?gpar , and have

Arrange base plots and grid.tables on the same page

廉价感情. 提交于 2019-11-26 22:30:28
I have 2 plots (created using Base graphics) and 2 data frames that I would like to combine onto one sheet in a PDF. I'm using grid.table to create a tableGrobs from my data frames. I'm having a lot of difficulty formatting the PDF output. In particular, I've been unsuccessful keeping all the objects on the same page. I want the right pannel to contain one graph, and the left panel to contain the other graph, and 2 tables below (landscape format). Currently my code is something like the following: library('gridExtra') pdf("Rplots.pdf", paper = "USr", height = 8.5, width = 11) layout(matrix(c(1

Grid of multiple ggplot2 plots which have been made in a for loop

梦想的初衷 提交于 2019-11-26 12:09:13
问题 as a new ggplot2 user, I am a bit lost with the amount of possibilities, and struggle to find on the net a simple answer to what I consider a simple problem. I would like to display multiple plots from ggplot2 on a same sheet, BUT knowing that these plots come from a for loop. Following example does not compile, it is only to illustrate : for(i in c(1:n)){ for(j in c(1:m)){ .......... # some data production p <- ggplot(df.all) + geom_bar(aes_string(x=class.names[i],fill=var.names[j]) }} Here,

Specifying ggplot2 panel width

岁酱吖の 提交于 2019-11-26 09:43:19
问题 I have two ggplots on the same page, and I\'d like their panels to be the same width. Some sample data: dfr1 <- data.frame( time = 1:10, value = runif(10) ) dfr2 <- data.frame( time = 1:10, value = runif(10, 1000, 1001) ) One plot below the other: p1 <- ggplot(dfr1, aes(time, value)) + geom_line() p2 <- ggplot(dfr2, aes(time, value)) + geom_line() grid.newpage() pushViewport(viewport(layout = grid.layout(2, 1))) print(p1, vp = viewport(layout.pos.row = 1, layout.pos.col = 1)) print(p2, vp =

How can I obtain an &#39;unbalanced&#39; grid of ggplots?

送分小仙女□ 提交于 2019-11-26 06:11:42
问题 With grid.arrange I can arrange multiple ggplot figures in a grid to achieve a multi-panel figure by using something like: library(ggplot2) library(grid) library(gridExtra) generate some ggplot2 plots , then plot5 <- grid.arrange(plot4, plot1, heights=c(3/4, 1/4), ncol=1, nrow=2) How can I obtain an \'unbalanced\' 2 col layout with one plot in the entire first col and three plots in the second col? I toyed with a \'grid-of-grids\' approach by trying to use grid.arrange to plot one grid (e.g.