grob

How to use empty space produced by facet_wrap?

若如初见. 提交于 2019-11-27 20:50:19
I have a faceted plot that forms an n x m grid. By design, the last (bottom-right) cell is always empty, so I'd like to utilize the extra space by adding another ggplot object. My current solution relies on low-level viewport approach, which is not very elegant and requires some hard-coding for position and size. Instead, I assume the empty space is reachable in some other fashion, probably with gridExtra ? Here's a minimal example for n=m=2 . Note that the edges are not aligned properly, so some extra work is required to manually adjust viewport's parameters, which is a pain, especially if (n

Inverse of ggplotGrob?

一曲冷凌霜 提交于 2019-11-27 18:18:50
I have a function which manipulates a ggplot object, by converting it to a grob and then modifying the layers. I would like the function to return a ggplot object not a grob. Is there a simple way to convert a grob back to gg? The documentation on ggplotGrob is awfully sparse. Simple example: P <- ggplot(iris) + geom_bar(aes(x=Species, y=Petal.Width), stat="identity") G <- ggplotGrob(P) ... some manipulation to G ... ## DESIRED: P2 <- inverse_of_ggplotGrob(G) such that, we can continue to use basic ggplot syntax, ie `P2 + ylab ("The Width of the Petal")` UPDATE: To answer the question in the

force a regular plot object into a Grob for use in grid.arrange

China☆狼群 提交于 2019-11-27 06:50:07
问题 b <- ggplot(cars,aes(x=speed,y=dist))+geom_line() grid.arrange( b, plot(cars), ncol=1 ) gives me the following error Error in gList(list(grobs = list(list(x = 0.5, y = 0.5, width = 1, height = 1, : only 'grobs' allowed in "gList" Let's assume my second graph has to come out of the plot function. How would one convert that output to a grob -like object so it plays nicely with grid.arrange ? 回答1: you can try with gridGraphics library(gridGraphics) grab_grob <- function(){ grid.echo() grid.grab(

R return corrplot as object

核能气质少年 提交于 2019-11-27 05:08:50
corrplot plots a correlation matrix, but it does not return a graphical object (grob) I would like to plot several correlation matrices on a single page. For normal plots, I would use grid.arrange from the gridExtra package. However since corrplot only prints and does not return an object, I can't see how to do this. Is there a workaround or a better alternative to corrplot ? There's the old standby par(mfrow=c(x, y)) where x is the number of rows you wish to plot and y the numberof columns. It then posts across and then down as you call the plots. par(mfrow = c(2, 2)) corrplot(cor(mat1))

How to place grobs with annotation_custom() at precise areas of the plot region?

只谈情不闲聊 提交于 2019-11-26 20:09:25
I am trying to reproduce the following [base R] plot with ggplot2 I have managed most of this, but what is currently baffling me is the placement of the line segments that join the marginal rug plot on the right of the plot with the respective label. The labels have been draw (in the second figure below) via anotation_custom() and I have used @baptiste's trick of turning off clipping to allow drawing in the plot margin. Despite many attempts I am unable to place segmentGrobs() at the desired locations in the device such that they join the correct rug tick and label. A reproducible example is y

Inverse of ggplotGrob?

两盒软妹~` 提交于 2019-11-26 19:23:18
问题 I have a function which manipulates a ggplot object, by converting it to a grob and then modifying the layers. I would like the function to return a ggplot object not a grob. Is there a simple way to convert a grob back to gg? The documentation on ggplotGrob is awfully sparse. Simple example: P <- ggplot(iris) + geom_bar(aes(x=Species, y=Petal.Width), stat="identity") G <- ggplotGrob(P) ... some manipulation to G ... ## DESIRED: P2 <- inverse_of_ggplotGrob(G) such that, we can continue to use

How to use empty space produced by facet_wrap?

安稳与你 提交于 2019-11-26 16:18:25
问题 I have a faceted plot that forms an n x m grid. By design, the last (bottom-right) cell is always empty, so I'd like to utilize the extra space by adding another ggplot object. My current solution relies on low-level viewport approach, which is not very elegant and requires some hard-coding for position and size. Instead, I assume the empty space is reachable in some other fashion, probably with gridExtra ? Here's a minimal example for n=m=2 . Note that the edges are not aligned properly, so

Seeking workaround for gtable_add_grob code broken by ggplot 2.2.0

随声附和 提交于 2019-11-26 12:46:24
问题 In plots with multiple facet variables, ggplot2 repeats the facet label for the \"outer\" variable, rather than having a single spanning facet strip across all the levels of the \"inner\" variable. I have some code that I\'ve been using to cover the repeated outer facet labels with a single spanning facet strip using gtable_add_grob from the gtable package. Unfortunately, this code no longer works with ggplot2 2.2.0 due to changes in the grob structure of the facet strips. Specifically, in

R return corrplot as object

半城伤御伤魂 提交于 2019-11-26 11:26:59
问题 corrplot plots a correlation matrix, but it does not return a graphical object (grob) I would like to plot several correlation matrices on a single page. For normal plots, I would use grid.arrange from the gridExtra package. However since corrplot only prints and does not return an object, I can\'t see how to do this. Is there a workaround or a better alternative to corrplot ? 回答1: There's the old standby par(mfrow=c(x, y)) where x is the number of rows you wish to plot and y the numberof