gtable

verticaly center table grobs in rmarkdown pdf

試著忘記壹切 提交于 2021-02-11 14:54:59
问题 I want to have my table grobs aligned to the top of each other but verticaly centered to the page with respect to the longest table. I need this to be automatic with tables of different lengths. This is what I have to vertically align them with each other as shown by @baptiste here. --- output: pdf_document geometry: - paperwidth=13.333in - paperheight=7.5in - margin=.5in --- ```{r, echo=F, fig.align='center'} library(magrittr) library(gridExtra) library(gtable) library(grid) # from https:/

R convert grid units of layout object to native

百般思念 提交于 2021-02-08 05:15:40
问题 My problem is somewhat related to Convert units from npc to native using grid in R . I'm trying to figure out the location of certain plot elements start in a ggplot2 object (axes, main plot, etc). I found the following code: rm(list = ls()) library(ggplot2) library(grid) library(gtable) # a dummy plot g <- ggplot(cars, aes(x = speed, y = dist)) + geom_point() g # a layout of each element obj <- ggplotGrob(g) l <- gtable:::gtable_layout(obj) grid:::grid.show.layout(l) All the information I

R convert grid units of layout object to native

北城余情 提交于 2021-02-08 05:14:35
问题 My problem is somewhat related to Convert units from npc to native using grid in R . I'm trying to figure out the location of certain plot elements start in a ggplot2 object (axes, main plot, etc). I found the following code: rm(list = ls()) library(ggplot2) library(grid) library(gtable) # a dummy plot g <- ggplot(cars, aes(x = speed, y = dist)) + geom_point() g # a layout of each element obj <- ggplotGrob(g) l <- gtable:::gtable_layout(obj) grid:::grid.show.layout(l) All the information I

ggplot geom_point: how to set font of custom plotting symbols?

烂漫一生 提交于 2021-02-04 17:56:09
问题 With ggplot::geom_point we are able to set any character for plotting symbols using scale_shape_manual . I am coming with an example which demonstrates the purpose: use triangles to make a heatmap with two values in each cell: require(ggplot2) data <- data.frame( val = rnorm(40), grp = c(rep('a', 20), rep('b', 20)), x = rep(letters[1:4], 5), y = rep(letters[1:5], 4) ) p <- ggplot(data, aes(x = x, y = y, color = val, shape = grp)) + geom_point(size = 18) + scale_shape_manual(values=c("\u25E4",

ggplot geom_point: how to set font of custom plotting symbols?

爷,独闯天下 提交于 2021-02-04 17:56:09
问题 With ggplot::geom_point we are able to set any character for plotting symbols using scale_shape_manual . I am coming with an example which demonstrates the purpose: use triangles to make a heatmap with two values in each cell: require(ggplot2) data <- data.frame( val = rnorm(40), grp = c(rep('a', 20), rep('b', 20)), x = rep(letters[1:4], 5), y = rep(letters[1:5], 4) ) p <- ggplot(data, aes(x = x, y = y, color = val, shape = grp)) + geom_point(size = 18) + scale_shape_manual(values=c("\u25E4",

Combine multiple facet strips across columns in ggplot2 facet_wrap

筅森魡賤 提交于 2020-07-06 23:25:48
问题 The bounty expires in 4 days . Answers to this question are eligible for a +50 reputation bounty. Björn wants to draw more attention to this question: It would be great to see a solution using grid & gtable without using additional packages. I am trying to combine facet strips across two adjacent panels (there is always two adjacent ones with the same first ID variable, but with two different scenarios, let's call them "A" and "B"). I am not particularly wedded to the gtable + grid solution I

Combine multiple facet strips across columns in ggplot2 facet_wrap

淺唱寂寞╮ 提交于 2020-07-06 23:25:11
问题 The bounty expires in 4 days . Answers to this question are eligible for a +50 reputation bounty. Björn wants to draw more attention to this question: It would be great to see a solution using grid & gtable without using additional packages. I am trying to combine facet strips across two adjacent panels (there is always two adjacent ones with the same first ID variable, but with two different scenarios, let's call them "A" and "B"). I am not particularly wedded to the gtable + grid solution I

Getting “npc” coordinates of ggplot2 grob

可紊 提交于 2020-03-23 08:20:08
问题 The grid package used for generating graphics in the R language uses so-called "normal parent coordinates" ( npc ) to position graphical objects (" grobs "). Is it possible to get the npc coordinates of a ggplot2 grob ? This would be of major help for drawing lines (for connecting data points) across facets (ggplot, drawing line between points across facets contains a solution, but this is very hard to follow for beginners) library(ggplot2) library(grid) # Generate some sample data df <- data

Text alignment and font size in gtable

爱⌒轻易说出口 提交于 2020-01-28 11:08:09
问题 My question relates to the answer by Baptiste that you can find here: https://stackoverflow.com/a/18667413/2072440. That code does pretty what I want it to do. I would like to make two modifications. First, I would like to align the text in the first column to the left. Second, I would like to change the font of the text. I have tried to edit the line that describes the fill for the cells' background but that does not seem to impact the font and it only impacts the position of the boxes

gtable: Put a black line around all cells in the table body

孤街醉人 提交于 2020-01-05 10:06:13
问题 I'm trying to put a relatively heavy line (say lwd = 2 size) around the body of a table using gridExtra . Here's a MWE slightly modified from this documentation page. gtable is doing the work under the hood but the documentation for gtable is thin; looking at the code didn't help much. g <- tableGrob(iris[1:4, 1:3], rows = NULL) separators <- replicate(1, segmentsGrob(x1 = unit(0,"npc")), simplify=FALSE) g <- gtable::gtable_add_grob(g, grobs = separators, t = 1, b = nrow(g), l = 1) g <-