Questions tagged [grob]

stands for **gr**aphical **ob**ject, the generic drawing component in the grid framework of R graphics. Grobs can be very primitive, such as text, rectangles, lines, or complex objects such as full plots built up from many lower-level components.

The recommended grid package is included in every distribution of the R software. As such, it provides a low-level framework for building up all kinds of static graphics. The core component of grid-based graphics is a grob, which in its most basic form is a generic class of objects that describe a graphical component. The most basic grobs are simple shapes such as pointsGrob, polygonGrob, etc., but new objects can be derived from those primitive objects, and are often assembled into a grob tree, or gTree, which holds together multiple shapes together with a specific layout.

Examples of high-level, complex grobs are the complete plots generated by the ggplot2 and lattice packages.

146 questions
2
votes
1 answer

Wrapping text in a tableGrob

I have a df with one column ("Reviewer Feedback") and two rows ("Reviewer 1" and "Reviewer 2"). I'm trying to wrap the text in the cells (the reviewer feedback) I keep getting an error: in gPathFromVector(names) : invalid grob…
vashfive
  • 21
  • 2
2
votes
1 answer

In R while using assign function, how can I store graphic objects to a list?

I have created the following function which takes a data frame and outputs multiple plots: boxplot_depend_vs_independ <- function(df_train) { train_int_names <- df_train %>% select_if(is.numeric) int_names <- names(train_int_names) …
Angel Cloudwalker
  • 2,015
  • 5
  • 32
  • 54
2
votes
1 answer

Control padding of grobs added to patchwork

This is a follow up problem to this question. The OP asked for a way to arrange parts of a plot in specific distances. I think teunbrand gave a very good answer. My own suggestion (extract the legend with cowplot, and stitch them to a plot in…
tjebo
  • 21,977
  • 7
  • 58
  • 94
2
votes
1 answer

How to draw a grob on top of ggplot?

I have a grob object (in my case it's euler plot) and a ggplot object, and I want to place one on top of another, for example: library(eulerr) library(ggplot2) df <- data.frame(a=sample(100),b=sample(50:149), c=sample(20:119)) venn <- euler(list( …
Vasily A
  • 8,256
  • 10
  • 42
  • 76
2
votes
0 answers

Making patchwork compatible with pdf creator using downloadHandler in Shiny?

I'm interested in using the patchwork package in arranging a set of plots, which the end user can then download using a download button. For simplicity I've only shown one plot in this example. Sample…
Nautica
  • 2,004
  • 1
  • 12
  • 35
2
votes
0 answers

R-marrangeGrob unique legend

I have a list of 45 ggplot objects that I'm arranging across multiple pages thanks to the marrangeGrob() function from gridExtra. I would like to show a same and unique legend on each pages. I know how to extract the legend (g_legend), how to plot…
cpas
  • 21
  • 2
2
votes
0 answers

Using R ggplot2 grobs to display plots. Is this causing a memory leak?

The following code seems to always increase memory use. Is there a memory leak? Is object_size(output) a good measure of memory being used by UI? Do I not understand how R reclaims memory? This is a simplified extract from an application that uses…
dcellis
  • 21
  • 2
2
votes
1 answer

Converting corrplot output to grob

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…
Garth
  • 21
  • 1
  • 2
2
votes
1 answer

Keeping plotted heights fixed when laying out a list ggplot together

I'm creating a list of ggplot heatmaps, which have the same number of rows but different number of columns and different lengths of their x-axis tick labels: plot.list <- vector(mode="list",length(3)) n.cols <- c(600,30,300) x.labs <-…
dan
  • 6,048
  • 10
  • 57
  • 125
2
votes
1 answer

r setting the size of a png device to the grob size

I have created a tableGrob T, this tableGrob can be of an altering size, according to previously given parameters. Is there a way to use the png() function so that the width and height parameters will be taken from the previously created…
Saar
  • 23
  • 4
2
votes
0 answers

cowplot: extracting subplot after calling plot_grid

I am using plot_grid to arrange two plots: library(ggplot2) library(cowplot) d = data.frame(x=rnorm(100), y=rnorm(100), g=sample(c('a', 'b'), 100, replace=T)) p1 = ggplot(d) + geom_point(aes(x=x, y=y, colour=g)) p2 = ggplot(d) + geom_point(aes(x=y,…
adn bps
  • 599
  • 4
  • 16
2
votes
4 answers

R tableGrob heatmap or conditional formating in column

Is there a way to create a similar effect to excel's conditional formating -> color scales in order to present a table in grid.table/tablegrob object? The color indicator should be red for the lower values and green for the higher values in the…
KRStam
  • 393
  • 5
  • 18
2
votes
1 answer

Transfor a Gif to a grob in R to use with annotation_custom in a ggplot

I am trying to import a gif and turn it into a grob to use it with the function annotation_custom in a ggplot, so far I imported it and have been able to turn it into an image. So far this is what I…
Derek Corcoran
  • 3,930
  • 2
  • 25
  • 54
2
votes
3 answers

Using arrangeGrob to add a sub plot as a legend

I'm trying to graph two plots together, where one I a main plot and the other is a sub plot that I'd like to be located in the legend area of the main plot. This code produces this plot: gLegend <- function(a.gplot){ tmp <-…
user1701545
  • 5,706
  • 14
  • 49
  • 80
2
votes
3 answers

R tableGrob change format of row

I have some relatively simple code to create a table for printing to a PDF: library(gridExtra) df <- head(iris) tableGrob(df, gp = gpar(fontsize = 8), rows = NULL) I'd like to make the last row the same format as the header row (bold, and darker…
ch-pub
  • 1,664
  • 6
  • 29
  • 52