grob

Inverse of ggplotGrob?

三世轮回 提交于 2021-02-17 06:30:10
问题 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

Converting corrplot output to grob

痞子三分冷 提交于 2021-01-28 03:27:40
问题 I am trying to use grid.arrange to combine multiple types of graph/table, one of which is a correlation matrix using corrplot . Is there a way to convert a corrplot to a grob or export/import as an image compatible with grid.arrange ? Since the other plots I'm combining are from ggplot and tableGrob, I can't seem to use par(mfrow = c(2, 2)) or layout(matrix(1:2)) as suggested in other posts. P1 <- corrplot(PANAcor, order="hclust", addgrid.col = "gray", type="full", col = col2(50), tl.cex=1.5,

Inverse of ggplotGrob?

帅比萌擦擦* 提交于 2021-01-07 06:57:07
问题 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

R: ggplot background gradient coloring

隐身守侯 提交于 2020-05-25 07:43:40
问题 I would like to generate ggplot’s with gradient coloring, filling both plot panel and its background, as herein shown. As you can see the gradient background coloring encompasses both plot panel and its background. At the moment, only an "approximation" of the required solution is known to me: library(ggplot2) library(grid) library(gridExtra) reds <- c("#7B0664", "#E32219") g <- rasterGrob(reds, width = unit(1, "npc"), height = unit(1, "npc"), interpolate = TRUE) ggplot(data = economics, aes

R: ggplot background gradient coloring

烈酒焚心 提交于 2020-05-25 07:42:46
问题 I would like to generate ggplot’s with gradient coloring, filling both plot panel and its background, as herein shown. As you can see the gradient background coloring encompasses both plot panel and its background. At the moment, only an "approximation" of the required solution is known to me: library(ggplot2) library(grid) library(gridExtra) reds <- c("#7B0664", "#E32219") g <- rasterGrob(reds, width = unit(1, "npc"), height = unit(1, "npc"), interpolate = TRUE) ggplot(data = economics, aes

R: ggplot background gradient coloring

雨燕双飞 提交于 2020-05-25 07:42:06
问题 I would like to generate ggplot’s with gradient coloring, filling both plot panel and its background, as herein shown. As you can see the gradient background coloring encompasses both plot panel and its background. At the moment, only an "approximation" of the required solution is known to me: library(ggplot2) library(grid) library(gridExtra) reds <- c("#7B0664", "#E32219") g <- rasterGrob(reds, width = unit(1, "npc"), height = unit(1, "npc"), interpolate = TRUE) ggplot(data = economics, aes

Locate title in top left of grid.arrange

房东的猫 提交于 2020-05-15 04:18:33
问题 I have two plots arranged side by side with gridExtra::grid.arrange . I can put a title on top of them with the top argument. Problem is, I was requested to locate the title on the top left of the plot. A reproducible example: library(ggplot2) library(gridExtra) p1 <- qplot(1:20) p2 <- qplot(30, 35) grid.arrange(p1, p2, nrow = 1, top = "Title") which produces But what I need is: I read several times the ?arrangeGrob file (I think there lies my answer), but haven't figured out how to achieve

Locate title in top left of grid.arrange

只谈情不闲聊 提交于 2020-05-15 04:18:06
问题 I have two plots arranged side by side with gridExtra::grid.arrange . I can put a title on top of them with the top argument. Problem is, I was requested to locate the title on the top left of the plot. A reproducible example: library(ggplot2) library(gridExtra) p1 <- qplot(1:20) p2 <- qplot(30, 35) grid.arrange(p1, p2, nrow = 1, top = "Title") which produces But what I need is: I read several times the ?arrangeGrob file (I think there lies my answer), but haven't figured out how to achieve

npc coordinates of geom_point in ggplot2

喜你入骨 提交于 2020-04-10 07:27:05
问题 How can I get the x , y coordinates of a geom_point in a ggplot , where the reference frame is the entire plotted image? I can create a ggplot with some geom_point s using: library(ggplot2) my.plot <- ggplot(data.frame(x = c(0, 0.456, 1), y = c(0, 0.123, 1))) + geom_point(aes(x, y), color = "red") This gives: By converting this into a grob , I can extract some additional information about this ggplot , like the coordinates with respect to the plot panel, marked by the purple arrow. However,

npc coordinates of geom_point in ggplot2

为君一笑 提交于 2020-04-10 07:27:04
问题 How can I get the x , y coordinates of a geom_point in a ggplot , where the reference frame is the entire plotted image? I can create a ggplot with some geom_point s using: library(ggplot2) my.plot <- ggplot(data.frame(x = c(0, 0.456, 1), y = c(0, 0.123, 1))) + geom_point(aes(x, y), color = "red") This gives: By converting this into a grob , I can extract some additional information about this ggplot , like the coordinates with respect to the plot panel, marked by the purple arrow. However,